#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    31
    Rep Power
    2

    Is this possible? SQL + Dynamic query?


    uhm, due to my limitations on sql server 2000, which are the nvarchar and varchar sizes (i need something that can hold a large character string for my query, which is possible in SQL server 2005 and up due to nvarchar(max)). could i do something like:



    select * from table1 @whereclause?

    where @whereclause = 'where id = 'A' or ID = 'b' or ID = 'C''

    sorry for the questions and thanks for the fine replies btw
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    101
    Rep Power
    9
    solution is

    declare @whereclause varchar(400)

    set @whereclause = 'where id = 'A' or ID = 'b' or ID = 'C'

    declare @sql varchar(8000)

    set @sql='select * from table1 ' + @whereclause

    exec @sql

IMN logo majestic logo threadwatch logo seochat tools logo