Dynamic SQL and IN list - Thanks!

anonymous_at_discussions.microsoft.com
Date: 06/10/04

  • Next message: Subir Kumar: "Pivot Query"
    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.
    >.
    >


  • Next message: Subir Kumar: "Pivot Query"

    Relevant Pages

    • Re: Full text catalog just not populating
      ... exec sp_defaultdb N'NT Authority\System', N'master' ... means either the network guys in my company who don't know SQL but are admins ... > needs this login to log into SQL Server and you can either add back this ... >> fetching U ...
      (microsoft.public.sqlserver.fulltext)
    • Re: Indexing delay for one row.
      ... script and WAITFOR and varying the delay from 1 to 18 seconds. ... could you confirm your exact version of SQL Server that you are seeing ... It is possible that a change was made to the pooling frequence under SP3 to ... exec sp_fulltext_table 'FTSTable','create','FTSCatalog','FTSTable_IDX' ...
      (microsoft.public.sqlserver.fulltext)
    • Re: storing and searching office docs in SQL
      ... You CAN both store and search the contents of the MS Word ... files stored in an SQL Table's FT-enable IMAGE column, ... FTS CONTAINS or FREETEXT to search the contents of that MS word document: ... exec sp_fulltext_database 'enable' -- only do this once! ...
      (microsoft.public.sqlserver.programming)
    • Re: SqlDataAdapter1.SelectCommand.CommandType= CommandType.StoredProcedure
      ... > kann man beim EXEC PROC keine Parameter beifügen. ... CommandType.StoredProcedure wird intern als RPC Command abgesetzt, ... SQL RPC siehe SQL Server Dokumentation, ... nach der Ausführung ungültig werden. ...
      (microsoft.public.de.german.entwickler.dotnet.datenbank)
    • pls help for the script!
      ... my script do not run with the parameter " ... exec sp_executesql @sql ... --Dummy-Tabelle Spaltenname erstellen ...
      (microsoft.public.de.vb.datenbank)