Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query..building a string !

Status
Not open for further replies.

fixthebug2003

Programmer
Oct 20, 2003
294
0
0
US
Hi,
I need a SQL which looks like this:

SELECT X,Y,Z FROM TABLE1 WHERE
TABLE1.NAME in (@variable1)

Now, this @variable1 should have values like this
'name1','name2','name3' that needs to be built (can have hard-coded values too)
so that the SQL query can execute...But how can I build this @variable1 in SQL Server 2000

thanks
Fixthebug2003
 
declare @sql varchar(1000)

-- sure this will be parameter
declare @variable1 varchar(10)

select @sql = 'SELECT X,Y,Z FROM TABLE1 '
select @sql = @sql + 'WHERE TABLE1.NAME in '
select @sql = @sql + @variable1

execute (@sql)

Delton

Not sure if this is what u want
 
I guess you did not get my question.
My question is: how to build a string with quotes in them?
 
Use a single quote twice to get a quote within a string

eg:

declare @variable varchar(100)

select @variable = '''hardcodedstring'''

select @variable

output will be:
'hardcoded string'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top