Simple update query

Hi all,
how to update a row with & in the it
the value is 'Antigua & Barbuda' When i update this as
update table_name set col_name='Antigua and Barbuda' where
col_name=''Antigua & Barbuda';
It is asking for col_name as & is there.
Please let me know how to update this column.
Thanks
Srinivas

Help stamp out the ampersands! (&)
It's on of SQL+ SET commands. DEF[INE]
Quoting from.....
otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a82950/ch8.htm#1009688
Note: You may have to edit out the '<br>'s put in by the Forum code to get the URL to work. Also you may have append some of the URL which may be truncated, usually the bookmark(#nnnn).
DEF[INE] {&|c|ON|OFF} Sets the character used to prefix substitution variables to c. ON or OFF controls whether SQL*Plus will scan commands for substitution variables and replace them with their values. ON changes the value of c back to the default '&', not the most recently used character. The setting of DEFINE to OFF overrides the setting of the SCAN variable. For more information on the SCAN variable, see the SET SCAN command in Appendix F.
Good Luck....

Similar Messages

  • Can not execute a simple update query with ms access

    Hi
    I am trying to execute a simple update query , this is the code I am running : I get no exeptions but the db is not being updated .
    When I copy my query into access it works !
    The table / columns are spelled correctly and I am able to execute select queries.
    can anyone figure out what is going on
    Thanks shahar
    public static void main(String[] args) {
    MainManager mainManager = MainManager.getInstance();
    Log log = Log.getInstance();
    try {
    log.writeDebugMessage("befor executing query");
    //stmt.executeUpdate("update trainee set Trainee_Name = 'shahar&Rafi' where Trainee_Id = 1 ");
    //stmt = null ;
    PreparedStatement stmt1 = con.prepareStatement("UPDATE Trainee SET Trainee_Name =? WHERE Trainee_Id =?");
    String name = new String("Shahar&Rafi");
    int Id = 1 ;
    stmt1.setString(1,name);
    stmt1.setInt(2,Id);
    System.out.println(stmt1.toString());
    stmt1.execute();
    log.writeDebugMessage("After executing query");
    catch (SQLException e ){
    System.err.println("SQLException: " + e.getMessage());
    }

    Hi All,
    got the problem solved at last.
    first, in the SQL string all the values must be within " ' "
    for example:
    INSERT INTO Trainee(Trainee_Id , Trainee_password , Trainee_Address, Trainee_Name , Trainee_Phone , Trainee_Gender , Trainee_SessionTime , Trainee_Purpose , Trainee_HealthStatus , Trainee_StartDate , Trainee_Birthday) VALUES (6,'333','hhhh','rafi',048231821,true,63,4,true, ('Feb 22, 2002'), ('Feb 22, 2002'))
    second and more important,
    a 'dummy' sql select query must be performed after an update query
    example for code:
    try{
    DB.MainManager.getInstance().ExecuteUpdateQuery(A);
    DB.MainManager.getInstance().getStatement().executeQuery("SELECT * FROM Trainee");
    where A is the update query.

  • Help simple update query

    Hi all,
    I have a simple update query problem. I have four tables
    activist(activist_id,first_name,last_name,c_state),
    membership(activist_id,g_n_id),
    group_network(g_n_id,g_n_type_id),
    school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
    Here is the query for the states which are null
    select distinct a.activist_id,a.first_name,a.last_name,
    a.c_state,sd.state from activist a,membership m,
    group_network g,school_group_det sd where
    a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
    g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
    order by a.activist_id
    I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
    Pleae any one help me
    Thanks
    Srinivas

    Hi all,
    I have a simple update query problem. I have four tables
    activist(activist_id,first_name,last_name,c_state),
    membership(activist_id,g_n_id),
    group_network(g_n_id,g_n_type_id),
    school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
    Here is the query for the states which are null
    select distinct a.activist_id,a.first_name,a.last_name,
    a.c_state,sd.state from activist a,membership m,
    group_network g,school_group_det sd where
    a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
    g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
    order by a.activist_id
    I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
    Pleae any one help me
    Thanks
    Srinivas

  • Simple Update query Will not work

    I am new to sql and I am doing an update query in access and it will not work, here is the query.
    UPDATE Change Code Master Table SET change code = '0';
    Edited by: 805337 on Oct 26, 2010 8:05 AM

    805337 wrote:
    I am new to sql and I am doing an update query in access and it will not work, here is the query.
    UPDATE Change Code Master Table SET change code = '0';
    Edited by: 805337 on Oct 26, 2010 8:05 AMI'm not at all sure why you are asking an MS Access question on an Oracle forum. Last I heard, Larry had not bought Microsoft yet.
    The MS Access equivalent to double quoting an identifier is square brackets like:
    UPDATE [Change Code Master Table] SET [change code] = '0';John

  • Update query against InfoPath form data

    Hi,
    We are using SharePoint Enterprise 2010, and have set up a series of InfoPath forms to manage various aspects of the projects we run (request forms, change control, toll gating, status reports, etc).  The forms are all created in InfoPath and save the
    data to form libraries on SharePoint.
    We are in the process of revamping the status report.  The fields for Accomplishments, Planned Activities, Risks and Dependencies were origianally set up as plain text.  We are moving to a bullted field for each.  My concern is that once we
    add the new fields to the published form, the old ones will disappear fom view.  So if we pull up an older status report, the information wont be available to view.
    Is there any way to write an update query against this form data?  Supposed I add a new bulleted field for "Accomplishments_NEW" and change the existing field to "Accomplishments_OLD".  If I were working with in Access, it would
    be a simple update query where the field selected would be "Accomplishments_NEW" and the update value would be "Accomplishments_OLD".  I have actually tried this through Access but we only seem to be able to read this data through
    Access, not write to it.
    Is there any way to make such a change on the SharePoint side?
    Dennis

    Yes.
    The approach is to add two fields:
    - Accomplishments_v2 and Accomplishments_v1_Loaded (true/false)
    when the form loads, if _v1_Loaded is false, migrate the data from the old field into _v2, and then set _v1_loaded = true
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • Doubt in Update query

    I have a problem using update query, for updating one column in a table with another column in another table. For eg say i have two tables, collector and survey
    Fields in Collector:
    col_n_account_num
    col_v_email
    col_n_phone_number
    Fields in survey
    sur_v_question_id
    sur_n_account_num
    sur_v_response
    update collector
    case when sur_v_question_id=collector_email then col_v_email=sur_v_response end,
    case when sur_v_question_id=collector_phone then col_n_phone_number=sur_v_response end
    Thanks in advance
    Regards,
    ss

    write two simple update statements
    update collector set col_v_email =
    (select sur_v_response from survey
    where sur_v_question_id=collector_email )
    and
    update collector set col_n_phone_number =
    (select sur_v_response from survey
    where sur_v_question_id=collector_phone)

  • A simple select query taking forever

    Hi All
    I am not able to execute a simple select query, I traced my session and here is TKPROF of that Trace.
    Solaris 8 , Oracle 10.2.0.4.0
    TKPROF: Release 10.2.0.4.0 -
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: 502_ora_28260.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select OBJECT_ID , ORACLE_USERNAME , SESSION_ID
    from
      v$locked_object
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.03      32.86          0          0          6           0
    total        3      0.03      32.86          0          0          6           0
    Misses in library cache during parse: 1
    Optimizer mode: CHOOSE
    Parsing user id: SYS
    Rows     Row Source Operation
          0  MERGE JOIN  (cr=0 pr=0 pw=0 time=60 us)
          0   SORT JOIN (cr=0 pr=0 pw=0 time=58 us)
          0    MERGE JOIN  (cr=0 pr=0 pw=0 time=42 us)
          1     SORT JOIN (cr=0 pr=0 pw=0 time=2443 us)
       1105      FIXED TABLE FULL X$KSUSE (cr=0 pr=0 pw=0 time=1204 us)
          0     SORT JOIN (cr=0 pr=0 pw=0 time=41 us)
       1001      FIXED TABLE FULL X$KTCXB (cr=0 pr=0 pw=0 time=16132 us)
          0   SORT JOIN (cr=0 pr=0 pw=0 time=0 us)
          0    FIXED TABLE FULL X$KTADM (cr=0 pr=0 pw=0 time=0 us)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
      buffer busy waits                              34        0.97         32.83
      SQL*Net break/reset to client                   1        0.00          0.00
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.03      32.86          0          0          6           0
    total        3      0.03      32.86          0          0          6           0
    Misses in library cache during parse: 1
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       2        0.00          0.00
      SQL*Net message from client                     1       19.00         19.00
      buffer busy waits                              34        0.97         32.83
      SQL*Net break/reset to client                   1        0.00          0.00
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        1  user  SQL statements in session.
        0  internal SQL statements in session.
        1  SQL statements in session.
    Trace file: 502_ora_28260.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           0  session in tracefile.
           1  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           1  SQL statements in trace file.
           1  unique SQL statements in trace file.
          64  lines in trace file.
          32  elapsed seconds in trace file. There is nothing fishy in alert logs... Please guide
    Thanks

    There it is TOP
    $ RUMPSHAKER>top
    load averages:  6.63,  7.45,  7.88;                    up 33+12:02:33           
    3631 processes: 3616 sleeping, 5 zombie, 1 stopped, 9 on cpu
    CPU states: 58.6% idle, 18.2% user, 23.2% kernel,  0.0% iowait,  0.0% swap
    Memory: 192G phys mem, 92G free mem, 96G swap, 96G free swap
       PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
    13752 ora0005    1  19    0 4243M 4219M sleep    5:21 62.78% oracle
    17758 ora0005    1  25    0 1174M 1156M cpu      1:05 37.12% oracle
    17923 root       1  57    0   18M   14M sleep  689:07 13.59% ecap_monitor
    20777 root      12  58    0   14M   13M sleep  864:33 11.55% OracleAgent
    18884 ora0004    1   1    0  830M  813M sleep    0:01  9.54% oracle
    12070 ora0004   61  58    0  320M  315M sleep   28.5H  8.29% emagent
    20347 root      16  59    0   33M   25M sleep   26.0H  6.34% caiUxsA2
    17949 ist0005    1  53    0 7984K 4984K cpu      0:00  3.93% top
         1 root       1  59    0 2912K 1288K sleep   32.2H  3.75% init
    15035 ora0001    1  46    0   32M   22M sleep  166:43  2.98% tnslsnr
      5748 ora0004   11  54    0  516M  496M sleep  389:37  2.78% oracle
    20567 ora0004    1  55    0   27M   22M sleep    0:00  2.69% sqlplus
      6730 ora0001    1  33    0  632M  616M sleep    0:06  2.67% oracle
    20557 ora0004    1  56    0   27M   23M sleep    0:00  2.53% sqlplus
      5355 ora0005    1  59    0 1154M 1137M sleep    0:04  2.46% oracleand VMSTAT 2 5
    $ RUMPSHAKER> vmstat 2 5
    kthr      memory            page            disk          faults      cpu
    r b w   swap  free  re  mf pi po fr de sr s0 s1 s2 sd   in   sy   cs us sy id
    6 8 0 143125576 74272080 4628 24012 488 150 149 0 0 4 4 -2 0 25037 192698 65249 38 26 36
    1 3 0 162803992 95246464 1989 6989 0 4 4 0 0 6 6 0  0 9170 57822 26434 8 13 79
    1 7 0 162801352 95240296 3043 15633 4 9737 9682 0 0 0 0 0 0 11277 73516 38200 16 16 68
    3 10 0 162801560 95227920 3326 12729 16 16862 16774 0 0 1 1 0 0 11377 86054 44758 16 17 68
    1 10 0 162784520 95186488 9638 48359 24 11682 11626 0 0 13 13 0 0 13484 149366 44205 23 29 47

  • "System Resource Exceeded" for simple select query in Access 2013

    Using Access 2013 32-bit on a Windows Server 2008 R2 Enterprise. This computer has
    8 GB of RAM.
    I am getting:
    "System Resource Exceeded"  errors in two different databases
    for simple queries like:
    SELECT FROM .... GROUP BY ...
    UPDATE... SET ... WHERE ...
    I compacted the databases several times, no result. One database size is approx 1 GB, the other one is approx. 600 MB.
    I didn't have any problems in Office 2010
    so I had to revert to this version.
    Please advise.
    Regards,
    M.R.

    Hi Greg. I too am running Access on an RDP server. Checking Task Manager, I can see many copies of MSACCESS running in the process list, from all users on the server. We typically have 40-60 users on that server. I am only changing the Processor Affinity
    for MY copy, and only when I run into this problem. Restarting Access daily, I always get back to multi-processor mode soon thereafter.
    As this problem only seems to happen on very large Access table updates, and as there are only three of us performing those kind of updates, we have good control on who might want to change the affinity setting to solve this problem. However, I
    understand that in other environments this might not be a good solution. In my case, we have 16 processors on the server, so I always take #1, my co-worker here in the US always takes #2, etc. This works for us, and I am only describing it here in case it
    works for someone else.
    The big question in my mind is what multi-threading methods are employed by Microsoft for Access that would cause this problem for very large datasets. Processing time for an update query on, say, 2 million records is massively improved by going down
    to 1 processor. The problem is easily reproduced, and so far I have not seen it in Excel even when working with very large worksheets. Also have not seen it in MS SQL. It is just happening in Access.

  • Not comitting database after the update query in jdbc

    Hi all,
    This is the first time I am posting this. I have query excuting on racle DB. This is update query. after executing the i have called commint using con.commit(). But still it is not showing the modifications in oracle db.
    What could be went wrong? Any sugestion, please let me know. I think it is simple jdbc program. So i don't think i need to post the code. Application running in Unix machine.
    Regards & thanks,
    Nirmala Vijaya Sekhar Varre

    VijayTechM wrote:
    Connection con = null;
    Class.forName("oracle.jdbc.driver.OracleDriver");          
    hi all,
    // following is the code
    con = DriverManager.getConnection("jdbc:oracle:thin:@10.129.239.43:1529:PBILLING","BILLING","BILLING");
    boolean test = con.getAutoCommit(); //here I am getting 'true'
    String invoice_header_query = "update invoice_header set file_traffico = '" + zipFileName + "' where bill_ref_no = '" + billRefNo_ + "' and bill_ref_resets = '" + billRefResets_ + "' and arbor_instance_id = '" + arborID_ + "'";
    System.out.println("invoice_header_query---->"+invoice_header_query);
    smt = con.createStatement();
    int x = stmt.executeUpdate(query); // Here x = 1 printing so it is updating the one record
    // con.commit(); // Even I have tried call this method. But this will be useful when you are using the Transactioon.
    Could you please tell me what went write. I am using ojdbc14.jar.
    regards,
    VijayPost with code tags and where is your claimed exception handling?

  • [JPA] CONCAT in update query

    Hello.
    I'm trying the new JPA API using TopLink and other implementations such as Hibernate.
    Everything in my simple tests seems to work fine, but an update query doesn't produce what i'm expecting. In this case, Hibernate works perfectly...
    For information i'm using the Derby database, version 10.1.2.1, in client-server mode, and the last build 36 of the TopLink glassfish JPA RI (from Oracle site)...
    The query works on a simple entity named 'Thing', trying to change a string/varchar property value using the CONCAT function :
    "update Thing t set t.description = CONCAT(t.description, '-UPDATED') where t.identifier like '%3-%'"
    Enabling finest logs, the following translation of the statement appears :
    UPDATE THING SET DESCRIPTION = VARCHAR(DESCRIPTION || '-UPDATED') WHERE (THING_IDENTIFIER LIKE '%3-%'
    I've tried the same SQL statement dierctly against the derby db, and for sure it doesn't work, ending with the same bad values ! For example, for an original field value "Test...T#3-1172242788995", the resulting updated value is "Test...T#3-1172" instead of the expected "Test...T#3-1172242788995-UPDATED"...
    An idea ? Should I specify the target derby base somewhere ?
    Thanks for your help...

    Hello.
    After more tests, it seems the problem comes from Derby, that truncates the strings using the VARCHAR function.
    Does any one know why Top Link uses the VARCHAR function for its translation of the JPA's CONCAT ?
    Thanks.

  • Update query (or other method) to a typed dataset

    Hi
    i have created a typed DataSet in code that is created at runtime. It gets populated then it needs to be updated based on 2 paramaters
    EmployeeID & AssignmentID
    How can i run an update query on the runtime created Dataset? Hee is how i create my Dataset-
    Private sGridDataSet As New DataSet("GridDataset")
    Private tblGridTable As DataTable
    sGridDataSet.CaseSensitive = False
    tblGridTable = sGridDataSet.Tables.Add("tblGrid")
    With tblGridTable
    .Columns.Add("AssignmentID", GetType(System.String))
    .Columns.Add("ProjectName", GetType(System.String))
    .Columns.Add("Day1", GetType(System.String))
    .Columns.Add("Day2", GetType(System.String))
    .Columns.Add("Day3", GetType(System.String))
    .Columns.Add("Day4", GetType(System.String))
    .Columns.Add("Day5", GetType(System.String))
    .Columns.Add("Day6", GetType(System.String))
    .Columns.Add("Day7", GetType(System.String))
    End With
    'get data from qryAssignments
    sAssignID = Me.AssignmentData.qryAssignments.Rows(j)(1)
    sProjName = Me.AssignmentData.qryAssignments.Rows(j)(0)
    newValues = {sAssignID, sProjName, Day1, Day2, Day3, Day4, Day5, Day6, Day7}
    tblGridTable.Rows.Add(newValues)
    Me.QryAssignmentsTableAdapter.ClearBeforeFill = True
    Dim sDate As Date = Me.txtDate.Text
    Dim EndDate As Date = sDate.AddDays(6)
    Me.QryAssignmentTimesTableAdapter.Fill(Me.AssignmentData.qryAssignmentTimes, Me.txtEmployeeID.Text, Me.txtDate.Text, CStr(CType(CStr(EndDate), DateTime)))
    Dim p As Integer = 0
    For p = 0 To Me.AssignmentData.qryAssignmentTimes.Rows.Count - 1
    vDayNo = Weekday(Me.AssignmentData.qryAssignmentTimes.Rows(p)(0), FirstDayOfWeek.Monday)
    Dim m As String = Me.AssignmentData.qryAssignmentTimes.Rows(p)(0)
    'NEED TO UPDATE DATASET TABLE HERE BASED ON EMPLOYEEID AND ASSIGNMENTID
    Next
    Me.GridControl1.DataSource = tblGridTable
    Hopefully, someone can give me a few pointers :)
    Thanks
    Nigel
    Nacho is the derivative of Nigel &amp;quot;True fact!&amp;quot;

    Hello,
    If I have more than one table to work with, a DataSet would be the container while if one table then no DataSet, just a DataTable. I would use code similar to the following which is for MS-Access yet by changing to SqlClient data provider instead of OelDb
    data provider the same methods work.
    Taken from
    this project.
    Module DatabaseOperations
    Private Builder As New OleDb.OleDbConnectionStringBuilder With
    .Provider = "Microsoft.ACE.OLEDB.12.0",
    .DataSource = IO.Path.Combine(Application.StartupPath, "Database1.accdb")
    ''' <summary>
    ''' Read USA customers from database into a DataTable
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks>
    ''' Database is assumed to be in the Bin\Debug folder.
    ''' </remarks>
    Public Function LoadCustomers() As DataTable
    Using cn As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
    Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
    cmd.CommandText =
    <SQL>
    SELECT
    Identifier,
    CompanyName,
    ContactName,
    ContactTitle,
    Address,
    City,
    PostalCode,
    Country
    FROM Customer;
    </SQL>.Value
    Dim dt As New DataTable With {.TableName = "Customer"}
    Try
    cn.Open()
    dt.Load(cmd.ExecuteReader)
    dt.Columns("Identifier").ColumnMapping = MappingType.Hidden
    dt.Columns("Country").ColumnMapping = MappingType.Hidden
    Catch ex As Exception
    MessageBox.Show("Failed to load customer data. See error message below" & Environment.NewLine & ex.Message)
    End Try
    dt.AcceptChanges()
    Return dt
    End Using
    End Using
    End Function
    Public Function RemoveCurrentCustomer(ByVal Identfier As Integer) As Boolean
    Try
    Using cn As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
    Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
    cmd.CommandText = "DELETE FROM Customer WHERE Identifier = ?"
    Dim IdentifierParameter As New OleDb.OleDbParameter With
    .DbType = DbType.Int32,
    .ParameterName = "P1",
    .Value = Identfier
    cmd.Parameters.Add(IdentifierParameter)
    Try
    cn.Open()
    Dim Affected = cmd.ExecuteNonQuery
    Return Affected = 1
    Catch ex As Exception
    Return False
    End Try
    End Using
    End Using
    Catch ex As Exception
    ' Handle or not handle exceptions for failed save operation
    Return False
    End Try
    End Function
    Public Function AddNewRow(ByVal Name As String, ByVal Contact As String, ByRef Identfier As Integer) As Boolean
    Dim Success As Boolean = True
    Try
    Using cn As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
    Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
    cmd.CommandText =
    <SQL>
    INSERT INTO Customer
    CompanyName,
    ContactName
    Values
    @CompanyName,
    @ContactName
    </SQL>.Value
    cmd.Parameters.AddWithValue("@CompanyName", Name)
    cmd.Parameters.AddWithValue("@ContactName", Contact)
    cn.Open()
    cmd.ExecuteNonQuery()
    cmd.CommandText = "Select @@Identity"
    Identfier = CInt(cmd.ExecuteScalar)
    End Using
    End Using
    Catch ex As Exception
    Success = False
    End Try
    Return Success
    End Function
    Public Function SaveChanges(ByVal sender As DataRow) As Boolean
    Try
    Using cn As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
    Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
    cmd.CommandText =
    <SQL>
    UPDATE
    Customer
    SET
    CompanyName=?,
    ContactName=?
    WHERE Identifier = ?
    </SQL>.Value
    Dim CompanyNameParameter As New OleDb.OleDbParameter With
    .DbType = DbType.String,
    .ParameterName = "P1",
    .Value = sender.Field(Of String)("CompanyName")
    cmd.Parameters.Add(CompanyNameParameter)
    Dim ContactNameParameter As New OleDb.OleDbParameter With
    .DbType = DbType.String,
    .ParameterName = "P2",
    .Value = sender.Field(Of String)("ContactName")
    cmd.Parameters.Add(ContactNameParameter)
    Dim IdentifierParameter As New OleDb.OleDbParameter With
    .DbType = DbType.Int32,
    .ParameterName = "P3",
    .Value = sender.Field(Of Int32)("Identifier")
    cmd.Parameters.Add(IdentifierParameter)
    Try
    cn.Open()
    Dim Affected = cmd.ExecuteNonQuery
    Return Affected = 1
    Catch ex As Exception
    Return False
    End Try
    End Using
    End Using
    Catch ex As Exception
    ' Handle or not handle exceptions for failed save operation
    Return False
    End Try
    End Function
    End Module
    Here is an example of retrieving a row of data via a where condition
    Public Sub LoadSingle(ByVal Identifier As Integer)
    Using cn As New OleDb.OleDbConnection With
    .ConnectionString = Builder.ConnectionString
    Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
    cmd.CommandText =
    <SQL>
    SELECT
    Identifier,
    CompanyName,
    ContactName
    FROM
    Customers
    WHERE Identifier=@Identifier
    </SQL>.Value
    cmd.Parameters.Add(New OleDb.OleDbParameter With
    .DbType = DbType.Int32,
    .ParameterName = "@Identifier",
    .Value = Identifier
    cn.Open()
    Dim Reader As OleDb.OleDbDataReader = cmd.ExecuteReader
    If Reader.HasRows Then
    Reader.Read()
    Console.WriteLine("Name: {0} Contact name: {1}",
    Reader.GetString(1), Reader.GetString(2))
    End If
    End Using
    End Using
    End Sub
    Here you can see (using a random example) that SQL-Server code uses the same logic and methods
    Using cn As New SqlConnection With {.ConnectionString = MyConnectionString}
    Dim CompanySearch As String = "An"
    Using cmd As New SqlCommand With {.Connection = cn}
    cmd.CommandText =
    <SQL>
    SELECT CompanyName
    FROM
    Customers
    WHERE
    CompanyName LIKE @CompanyName
    </SQL>.Value
    cmd.Parameters.Add(
    New SqlParameter With
    .DbType = DbType.String,
    .Value = CompanySearch & "%",
    .ParameterName = "@CompanyName"
    cn.Open()
    Dim Reader = cmd.ExecuteReader
    If Reader.HasRows Then
    While Reader.Read
    Console.WriteLine(Reader.GetString(0))
    End While
    Else
    Console.WriteLine("No matches")
    End If
    End Using
    End Using
    So all the above is "hand coding" and there is still the option to use Adapters but for simple stuff they are over kill. The only benefit for them with simple stuff is if you are a visual person, thats it.
    See also:
    This article on creating SQL statement as per how I did it in the examples above. In the next release of Visual Studio this method will be easier similar to C#
    Currently in C# we can do this
    string selectStatement = @"
    SELECT CompanyName
    FROM
    Customers
    WHERE
    CompanyName LIKE @CompanyName";
    On creating a DataTable, check out this simple utility
    https://code.msdn.microsoft.com/DataTable-creator-95b655b3
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Update query doubt

    I have table with two columns as given below ....
    Name sex
    ab m
    ac m
    ad m
    ae m
    ba f
    bb f
    bc f
    bd f
    I have to change all 'm' to 'f' and all 'f' to 'm'..... I have tried this using rowid and collection and I was able to do this. Is there other way to do this with simple SQL query????? Please somebody help....
    thanks in advance
    Prabu.....

    update your_table
    set    s_e_x = (case s_e_x
                         when 'm' then 'f'
                         when 'f' then 'm'
                    end
    where s_e_x in ('m','f');

  • Unanle to run update query

    Hi Experts,
    I got the solution from SAP to run update query on table E071 by using SQLPLUS prompt.
    But when I run this query I am getting message as below:
    ERROR at line 1:
    ORA-00942: table or view does not exist
    I am also unable to execute simple query like
    - select * from E071;
    - desc E071;
    For all above queries I am getting the same message as shown.
    But I am able to open view the table in SE11.
    I am also able to execute the following query in sqlplus -
    - select owner, table_name from all_tab_cols where table_name like 'E071';
    - select * from all_tables where table_name like 'E071';
    Please provide me the solution / alternative to run this update query on table E071.
    Thanks in Advance
    Best RG//
    Ramesh.

    Hi,
    if you use
    sqlplus / as sysdba
    you are SYS to the DB. You need to specify the schemauser.
    desc sapr3.E071
    desc sapsr3.E071
    desc sapsid.E071
    depending on how you schemauser is named.
    check your sidadm environment:
    env | grep -i schema
    Hope this helps
    Volker

  • If statement in update query

    I was wondering if you could have a cfif statement inside of a update query.  See example below.  Is there a better way of doing it? thanks.
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = #URL.var0#
                <cfif IsDefined("URLvar13">
                ,Q1_answer = #URL.var13#
                </cfif>
            WHERE ID = #session.member_id#
      </cfquery>

    TheScarecrow,
    Yes, dynamic query statements can be assembled using <cfif>.  I would suggest you switch your IsDefined() to a StructKeyExists() and strongly suggest you make good use of <cfqueryparam>:
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = <cfqueryparam value="#URL.var0#" cfsqltype="****">
                <cfif StructKeyExists(URL, "var13")>
                ,Q1_answer = <cfqueryparam value="#URL.var13#" cfsqltype="****">
                </cfif>
            WHERE ID = <cfqueryparam value="#session.member_id#" cfsqltype="****">
      </cfquery>
    I put a "****" placeholder for cfsqltype attributes because I'm not sure which would be appropriate for your variables.  See the help docs for more on the cfqueryparam and cfsqltype.
    -Carl V.

  • Insert and update query to calculate the opening and closing balance

    create table purchase(productid number(5) ,dateofpurchase date,
    qty number(5));
    create table inventory(invid number(5),productid number(5),
    idate date,openingqty number(5),closingqty number(5));
    Records in inventory:
    1,1,'01-jan-2009', 10, 20
    2,1,'03-jan-2009', 20, 30
    3,1,'04-jan-2009', 40, 50
    when I enter the purchase invoice for 15 qty on 02-jan-2009
    after say '15-jan-09' , a new record should get inserted
    with opening balance = (closing balance before 02-jan-2009)
    and all the opening and closing balance for that product should
    get affected.
    If the invoice for 20 qty is entered for the existing date say
    '03-jan-2009' in inventory , then the closing balance
    for 03-jan-2009 should get updated and all the following records
    should get affected.
    I need the insert for the first one and update query for the
    second one.
    Vinodh

    <strike>You can do this in one statement by using the merge statement</strike>
    Hmm, maybe I spoke too soon.
    Edited by: Boneist on 25-Sep-2009 13:56
    Thinking about it, why do you want to design your system like this?
    Why not simply have your purchases table hold the required information and then either work out the inventory on the fly, or have a job that calls a procedure to add a row for the previous day?
    If you continue with this design, you're opening yourself up to a world of pain - what happens when the data doesn't match the purchases table? Also when is the inventory cut-off to reset the opening/closing balances? Monthly? Annually? Weekly? If it's set to one of those, what happens when the business request the inventory for a particular week?
    Edited by: Boneist on 25-Sep-2009 13:59

Maybe you are looking for