Loading ...
Sorry, an error occurred while loading the content.

Result from Update Statement

Expand Messages
  • Arun Ladha
    Dear Sir, I want to get incremental value from a table. For this first I have to execute UPDATE statement than I have to execute SELECT statement to get that
    Message 1 of 7 , Aug 31, 2006
    • 0 Attachment
      Dear Sir,
      I want to get incremental value from a table. For this first I have to execute UPDATE statement than I have to execute SELECT statement to get that Updated Value. Can I get result from a single Statement. Please help me.
      Sample Code is Given here

      CREATE TABLE AutoNumber (TableName VarChar(20), FieldName VarChar(25), SerialNumber int)
      GO
      INSERT INTO AutoNumber VALUES ('HeaderTable', 'SrlNo', 500)
      INSERT INTO AutoNumber VALUES ('DetailTable', 'SrlNo', 950)
      INSERT INTO AutoNumber VALUES ('DetailTable', 'Serial', 300)
      INSERT INTO AutoNumber VALUES ('FooterTable', 'SrlNo', 50)
      GO
      UPDATE AutoNumber SET SerialNumber = SerialNumber + 1 WHERE TableName = 'HeaderTable' AND FieldName = 'SrlNo'
      GO
      SELECT SerialNumber FROM AutoNumber WHERE TableName = 'HeaderTable' AND FieldName = 'SrlNo'
      GO



      Thanks

      Arun Ladha


      ---------------------------------
      Here's a new way to find what you're looking for - Yahoo! Answers
      Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW

      [Non-text portions of this message have been removed]
    • Arnie Rowland
      Perhaps this will work for you. DECLARE @NewSerialNumber int UPDATE AutoNumber SET SerialNumber = ( SerialNumber + 1 ) , @NewSerialNumber = ( SerialNumber + 1
      Message 2 of 7 , Sep 1, 2006
      • 0 Attachment
        Perhaps this will work for you.

        DECLARE @NewSerialNumber int

        UPDATE AutoNumber
        SET
        SerialNumber = ( SerialNumber + 1 )
        , @NewSerialNumber = ( SerialNumber + 1 )
        WHERE ( TableName = 'HeaderTable'
        AND FieldName = 'SrlNo'
        )

        SELECT @NewSerialNumber

        - Arnie Rowland

        "I am a great believer in luck, and I find that the harder I work, the more
        I have of it." - Thomas Jefferson (1743-1826)


        -----Original Message-----
        From: SQLQueriesNoCode@yahoogroups.com
        [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Arun Ladha
        Sent: Friday, September 01, 2006 5:24 PM
        To: Arnie
        Subject: [SQLQueriesNoCode] Result from Update Statement

        Dear Sir,
        I want to get incremental value from a table. For this first I have to
        execute UPDATE statement than I have to execute SELECT statement to get that
        Updated Value. Can I get result from a single Statement. Please help me.
        Sample Code is Given here

        CREATE TABLE AutoNumber (TableName VarChar(20), FieldName VarChar(25),
        SerialNumber int)
        GO
        INSERT INTO AutoNumber VALUES ('HeaderTable', 'SrlNo', 500)
        INSERT INTO AutoNumber VALUES ('DetailTable', 'SrlNo', 950)
        INSERT INTO AutoNumber VALUES ('DetailTable', 'Serial', 300)
        INSERT INTO AutoNumber VALUES ('FooterTable', 'SrlNo', 50)
        GO
        UPDATE AutoNumber SET SerialNumber = SerialNumber + 1 WHERE TableName =
        'HeaderTable' AND FieldName = 'SrlNo'
        GO
        SELECT SerialNumber FROM AutoNumber WHERE TableName = 'HeaderTable' AND
        FieldName = 'SrlNo'
        GO



        Thanks

        Arun Ladha


        ---------------------------------
        Here's a new way to find what you're looking for - Yahoo! Answers
        Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get
        it NOW

        [Non-text portions of this message have been removed]






        Yahoo! Groups Links










        Disclaimer - September 1, 2006
        This email and any files transmitted with it are confidential and intended solely for SQLQueriesNoCode@yahoogroups.com. If you are not the named addressee you should not disseminate, distribute, copy or alter this email. Any views or opinions presented in this email are solely those of the author and might not represent those of Westwood Consulting, Inc. Warning: Although Westwood Consulting, Inc has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.
        This disclaimer was added by Policy Patrol: http://www.policypatrol.com/


        [Non-text portions of this message have been removed]
      • Sue Hoffman
        Hi: Can any one please help me in creating query.I input from user the account number, Technician ID and then search the match in table tech_id with
        Message 3 of 7 , Sep 3, 2006
        • 0 Attachment
          Hi: Can any one please help me in creating query.I input from user the account number, Technician ID and then search the match in table tech_id with tech_id.CORP and tech_id.TECH and print the tech_id.TECHCONT. In table tech_id the CORP is equals to the first five digit of account number in both tables. I have to search the account number in both tables (Tbl_ValidDispute,tbl_PPVResearch). Tbl_ValidDispute and Tbl_PPVResearch they both are connected with TicketNum.In tbl_PPVResearch there are three fields (FS_TechID1, FS_TechID2, FS_TechID3). If FS_TechID3 is not empty means its a lastvalidtechnician or if FS_TechID2 is not empty and FS_TechID3 is empty it means FS_TechID2 is a lastavlidtechnician otherwise FS_TechID1 is a last valid technician.

          Same in Tbl_ValidDispute i have to search all three otheraccounts. First if otherAcct3 is not empty and match with tech_id.CORP also match the LstVldTech with tech_id.TECH and if they both match then print the TECHCONT. If otherAcct3 is empty but otherAcct2 is not empty then match with tech_id.CORP also match LstVldTech with tech_id.TECH if both match then print the tech_id.TECHCONT. if otherAcct2 and otherAcct3 is empty then match with otherAcct1 and print the TECHCONT.
          Thanks,
          ---------------------------------------------------------
          tbl_PPVResearch
          ---------------
          TicketNumAccountNum FS_TechID1 FS_TechID2 FS_TechID3
          328 07836-033752-01 309
          329 07882-022113-12 786
          330 07837-026980-07 773
          334 07837-337410-03 590
          335 07876-537867-04 222
          336 07868-580112-06 643
          348 07876-579223-02 228
          349 07875-192714-06
          351 07870-451873-05
          352 07840-940441-02 101 20
          353 07818-242399-05 71
          356 07844-251648-08 85 415 415
          362 07862-215662-01 304 70
          366 07840-356692-02 119
          377 07836-421118-01 522
          392 07869-874266-02 316
          395 07872-119872-03 419 669 538
          397 07844-071040-06 471
          400 07804-006655-05 369
          402 07876-523152-01 CUST PICKUP
          409 07836-596979-01 713 424 185
          423 07870-739378-03 373
          427 07883-596396-05 855 214
          431 07836-547313-02 557
          Tbl_ValidDispute
          ----------------
          TicketNum OtherAcct1 OtherAcct2 OtherAcct3 LstVldTech
          478 07837-237258-02 07837-335799-01 07237-404300-01 251
          647 07837-443814-01 07837-421471-05
          743 07837-22220-02
          761 07837-5690-01 07837-474611-02
          751 07837-531065
          1004 07837 242858-02
          1450 07836-640954-02 678
          1495 07837-024196-04 261

          tech_id
          -------
          CORP TECH TECHCONT
          07883 214 Fuentes
          07836 185 Cruz
          07837 261 Long
          07837 251 Bing
          07801 415 Messina
          07801 416 Malgliolo
          07801 417 Malgliolo


          ---------------------------------
          Get your email and more, right on the new Yahoo.com

          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.