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.
Author |
Topic |
girishkardam
Starting Member
13 Posts |
Posted - 2008-09-19 : 07:41:44
|
Hi I had created procedure and passing tablename & columnname as parameter. I am using passed tablename & columnname in below format set @sql = 'select count(*) from '+ @tablename + ' where '+ @columnname + ' Like '+ '%Script%'exec(@sql)but procedure is not working properly and showing error for '%Script%' while executing it bcz while executing the query '%Script%' is read as %Script% by sql server. Kindly guide me how i can handle this condition. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-19 : 07:50:39
|
do like below:-set @sql = 'select count(*) from '+ @tablename + ' where '+ @columnname + ' Like ''%Script%''' |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-19 : 07:51:47
|
also read below to understand about single quoteshttp://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx |
 |
|
girishkardam
Starting Member
13 Posts |
Posted - 2008-09-19 : 08:07:27
|
Hi visakh thanks it working fine |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-19 : 09:44:40
|
quote: Originally posted by girishkardam Hi visakh thanks it working fine
welcome |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-09-19 : 10:40:57
|
Better yet, read up on sp_executeSQL -- using parameters is always the best way to write stuff like this.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
|
|