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)
 single quotes - escape character

Author  Topic 

varalakshmi
Yak Posting Veteran

98 Posts

Posted - 2010-07-23 : 05:20:19
Hi,
I use stored procedure to execute queries.
The query look like the one below:
SET @sql = 'SELECT * FROM TABLE WHERE COLUMN ='+ @value

Here @value will have value like dbo.TABLE1
This results in the error :
The multipart identifier 'dbo.TABLE1' could not be bound.

How can this be resolved? I'm not able to use single quotes here for the value. What character can be used as escape character for single quote?

Thanks
Varalakshmi.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-07-23 : 05:32:14
SET @sql = 'SELECT * FROM TABLE1 WHERE COLUMN ='''+ @value +''''

For more info:

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-23 : 05:36:12
Column='dbo.Table1' ???


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page
   

- Advertisement -