Wednesday, March 17, 2010

Set with Select

Today's forehard slap is brought to you by the following:

This is a perfectly valid syntax for setting a local variable using SET which gets its value from a SELECT:
set @VAR1 = (select var1 from table1 (nolock) where var2 = @var2 and var3 = @var3)

This will bring your company to a grinding halt and leave everyone breathing down your neck till you fix it:
set @VAR1 = select var1 from table1 (nolock) where var2 = @var2 and var3 = @var3

Be careful to note and recall the difference.

1 comment:

  1. Hi,
    If you want to see those exit codes actually used, have a look at www.robocopyplus.com.
    it acts liek a wrapper around robocopy to add swicthes for email notification and report filtering

    ReplyDelete