Announcement

Collapse
No announcement yet.

sql query to increment a number

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • sql query to increment a number

    i have found this query, but anyone can explain complete syntax for the insert query in sc:

    SELECT MAX(IDN) FROM dbo.MyTable

    UPDATE dbo.MyTable
    SET IDN = IDN + (SELECT MAX(IDN) FROM dbo.MyTable)

  • #2
    Andrea,

    Need more information. What are you trying to accomplish?
    I am guessing that you might want to investigate auto-increment: http://dev.mysql.com/doc/refman/5.0/...increment.html
    Dave Prue
    Code Whisperer
    Lahar International Corp
    www.lahar.net

    Comment


    • #3
      reading the query should work, but I read that I have to use the syntax and add, say, $ check_sql = ........ etc, and 'then sc_lookup (rs, $ check_sql); but as a whole the code with the query. thanks Regards

      Comment


      • #4
        What is it that u are trying to accomplish?

        1. If you use Mysql database you easily set the the Prime Key (PK ) in your tabel to autoincrement, so then the database will take care of it.
        2. If you need another table in a Foreign Key situation you can use a stored procedure to handle that correcty

        then you don't need any special SQL in scriptcase that.

        Comment


        • #5
          My example

          i have method incnumquoation.


          // SQL statement parameters
          $update_table = 'erp.dbo.SEQUENCENUMBER'; // Table name
          $update_fields = array("NEXTREC = '{dssec[0][0]}+1'",);
          $update_where = "DATAAREAID='dpm' and NUMBERSEQUENCE ='QUOTATION'"; // Where clause

          // Update record
          $update_sql = 'UPDATE ' . $update_table
          . ' SET ' . implode(', ', $update_fields)
          . ' WHERE ' . $update_where;
          sc_exec_sql($update_sql);

          Comment

          Working...
          X