Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic Strings in Sql 2005

Author  Topic 

svicky9
Posting Yak Master

232 Posts

Posted - 2007-05-05 : 16:08:08
Hi Friends

i am trying to create dynamic strings in Sql 2005

Eg:

declare @sql nvarchar(1000)

set @sql=''
set @sql= @sql+'select customername from customers'
print @sql

---The Above Example Prints the Statement


--Now


Eg :2


declare @string nvarchar(200)
declare @sql nvarchar(1000)
declare @c_id nvarchar(1000)
declare @tablename varchar(100)
declare @sstring varchar(100)

set @c_id = 'customerid'
set @tablename ='customers'
set @sstring ='alfki'


set @sql=@sql+'insert into sql_search select ['+@c_id+'] from '+@tablename+' where ['+@c_id+'] like '+@sstring
print @sql

--The Above Eg 2 does not print

Is it something to do with string concatenation???

cheers

Vic

svicky9
Posting Yak Master

232 Posts

Posted - 2007-05-05 : 16:15:20
thanks friends...figured it out...just setting @sql =''

Vic
Go to Top of Page
   

- Advertisement -