DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Thread: Better SQL Code

  1. #1
    Edwin Guest

    Better SQL Code


    Hello All,
    I have a set of upate queries that run in a SQL Stored Procedure on MSSQL2000.
    That look like this:

    IF @Corrections NOT IN (SELECT [Corrections] FROM [WEB_WIPSTATNEW]
    WHERE [WEB_WIPSTATNEW].[JobNumber] = @jobnumber
    AND [WEB_WIPSTATNEW].[BoardNumber] = @boardnumber)

    BEGIN
    UPDATE [WEB_WIPSTATNEW]
    SET
    [Corrections] = @corrections,
    [CorrectionsDate] = @current_datetime,
    [CorrectionsAuth] = @user

    WHERE [WEB_WIPSTATNEW].[JobNumber] = @jobnumber
    and [WEB_WIPSTATNEW].[Boardnumber] = @BoardNumber
    END

    I have more than twenty of these in there. I'm sure that there is a more
    efficient way to write this, any ideas? Thanks in advance!

  2. #2
    Yuji Guest

    Re: Better SQL Code


    IF NOT EXISTS (SELECT Corrections
    FROM WEB_WIPSTATNEW
    WHERE job.Number = @jobNumber
    AND BoardNumber = @boardNumber
    AND corrections = @corrections)

    UPDATE WEB_WIPSTATNEW
    SET Corrections = @corrections,
    CorrectionsDate = @current_datetime,
    CorrectionsAuth = user
    WHERE JobNumber = @jobNumber
    AND BoardNumber = @boardNumber

    "Edwin" <vbedluciano@hotmail.com> wrote:
    >
    >Hello All,
    >I have a set of upate queries that run in a SQL Stored Procedure on MSSQL2000.
    >That look like this:
    >
    >IF @Corrections NOT IN (SELECT [Corrections] FROM [WEB_WIPSTATNEW]
    > WHERE [WEB_WIPSTATNEW].[JobNumber] = @jobnumber
    > AND [WEB_WIPSTATNEW].[BoardNumber] = @boardnumber)
    >
    > BEGIN
    > UPDATE [WEB_WIPSTATNEW]
    > SET
    > [Corrections] = @corrections,
    > [CorrectionsDate] = @current_datetime,
    > [CorrectionsAuth] = @user
    >
    >WHERE [WEB_WIPSTATNEW].[JobNumber] = @jobnumber
    > and [WEB_WIPSTATNEW].[Boardnumber] = @BoardNumber
    > END
    >
    >I have more than twenty of these in there. I'm sure that there is a more
    >efficient way to write this, any ideas? Thanks in advance!



  3. #3
    Edwin Guest

    Re: Better SQL Code


    THANK YOU SO MUCH

    "Yuji" <ynakagawa@devx.com> wrote:
    >
    >IF NOT EXISTS (SELECT Corrections
    > FROM WEB_WIPSTATNEW
    > WHERE job.Number = @jobNumber
    > AND BoardNumber = @boardNumber
    > AND corrections = @corrections)
    >
    > UPDATE WEB_WIPSTATNEW
    > SET Corrections = @corrections,
    > CorrectionsDate = @current_datetime,
    > CorrectionsAuth = user
    > WHERE JobNumber = @jobNumber
    > AND BoardNumber = @boardNumber
    >
    >"Edwin" <vbedluciano@hotmail.com> wrote:
    >>
    >>Hello All,
    >>I have a set of upate queries that run in a SQL Stored Procedure on MSSQL2000.
    >>That look like this:
    >>
    >>IF @Corrections NOT IN (SELECT [Corrections] FROM [WEB_WIPSTATNEW]
    >> WHERE [WEB_WIPSTATNEW].[JobNumber] = @jobnumber
    >> AND [WEB_WIPSTATNEW].[BoardNumber] = @boardnumber)
    >>
    >> BEGIN
    >> UPDATE [WEB_WIPSTATNEW]
    >> SET
    >> [Corrections] = @corrections,
    >> [CorrectionsDate] = @current_datetime,
    >> [CorrectionsAuth] = @user
    >>
    >>WHERE [WEB_WIPSTATNEW].[JobNumber] = @jobnumber
    >> and [WEB_WIPSTATNEW].[Boardnumber] = @BoardNumber
    >> END
    >>
    >>I have more than twenty of these in there. I'm sure that there is a more
    >>efficient way to write this, any ideas? Thanks in advance!

    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links