Dynamic SQL and IN list - Thanks!
anonymous_at_discussions.microsoft.com
Date: 06/10/04
- Previous message: Amelia: "Dynamic SQL and IN list - Thanks!"
- In reply to: Amelia: "Dynamic SQL and IN list - Thanks!"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 9 Jun 2004 18:40:34 -0700
How embarassing! I figured it out.
Solution 3 works. I incorrectly had my concat. string
after the @sql since I was modifying some previous sql.
The below works in case anyone else finds this handy!
declare @sSql nvarchar(500)
declare @sParameters nvarchar(500)
declare @sPremises nvarchar(50)
set @sPremises = '25, 10'
set @sSql = 'Select * from PREMISE where premises IN ('
+@sPremises+ ')'
EXEC sp_executesql @sSql
>-----Original Message-----
>I am trying to get dynamic SQL working with an IN list
and
>can't find any answers in the SQL Server Help.
>
>1)I can get a simple parameter working as below
>
>declare @sSql nvarchar(500)
>declare @sParameters nvarchar(500)
>declare @sPremises varchar(10)
>
>set @sSql = 'Select * from PREMISE where premises =
>@sPremises'
>set @sParameters = '@sPremises varchar(10)'
>
>EXEC sp_executesql @sSql, @sParameters, @sPremises = '25'
>
>2)BUT I cannot get this to work
>
>declare @sSql nvarchar(500)
>declare @sParameters nvarchar(500)
>declare @sPremises varchar(10)
>
>set @sSql = 'Select * from PREMISE where premises IN
>(@sPremises)'
>set @sParameters = '@sPremises varchar(50)'
>
>EXEC sp_executesql @sSql, @sParameters, @sPremises = '25,
>10'
>
>3) I also tried the following which executes but with no
>results.
>
>declare @sSql nvarchar(500)
>declare @sParameters nvarchar(500)
>declare @sPremises nvarchar(50)
>
>
>set @sSql = 'Select * from PREMISE where premises IN ('+
>@sPremises +')'
>set @sPremises = '25, 10'
>
>EXEC sp_executesql @sSql
>
>Is there a way to do this - Thanks for the assistance
>:0) A.
>.
>
- Previous message: Amelia: "Dynamic SQL and IN list - Thanks!"
- In reply to: Amelia: "Dynamic SQL and IN list - Thanks!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|