You can't do what you want with Exec. Instead, try using the sp_executesql
stored proc with output parameters. Something like this:
declare @params nvarchar(255)
declare @numContacts int
set @params = N'@n... int OUTPUT'
set @StrSQL = "SELECT @numContactsOUT = count(*) FROM TABLE_NAME where
ContactID in (" + @contactIds + ")"
execute sp_executesql @StrSQL, @params, @numContactsOUT=@numContacts OUTPUT
-Lam
>
Hi All,
Please let me know if we can store the value of the Exec SQLSTATEMENT to a
variable.
Eg :
DECLARE @StrSQL Varchar(200)
DECLARE @ContactIds Varchar(15)
SET @ContactIds="4,6,14"
Select @StrSQL="SELECT count(*) FROM TABLE_NAME where ContactID in (" +
@ContactIds + ")"
This returns 3 as a result. I would like to check its output, if the
result=0 then I will have to drop the plan of updating them, else I would
continue to update there on.
I am looking for storing this Value into a variable or use it directly in
IF statement and go accordingly. But from my search in BOL, I dont think
we can either store them into Variable or use in IF statement directly.
Can anyone suggest me a way to go about it?
Thanks
-- Vijay G
---------------------------------
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site