none
If not Exist Insert Query

    Question

  • Hi I have the syntax for the following query but dont understand why  UsePrimayKeyHere = 'UsePrimaryKeyHere' is in Where clause?

    IF NOT EXISTS

    (SELECT 1 FROM [EligStaging].[Uaqa].[CrosswalkTableNameHere]

     WHERE [UsePrimaryKeyHere] = UsePrimaryKeyHere')

    BEGIN

    INSERT INTO [EligStaging].[Uaqa].[CrosswalkTableNameHere]

               ([FieldName1] ,[FieldName2], [AndSoOn…])

         VALUES

               ([FieldName1Value] ,[FieldName2Value], [AndSoOn…])

    END

    Thanks

    Monday, October 18, 2010 5:27 PM

Answers

  • Because you are checking to see if PRIMARY KEY is exist or not. If it is not then INSERT new record.
    Best Wishes, Arbi --- Please vote if you find this posting was helpful or Mark it as answered.
    • Marked as answer by SqlRockss Monday, October 18, 2010 5:50 PM
    Monday, October 18, 2010 5:30 PM