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 quote in data interpreted incorrectly

Author  Topic 

jar21

51 Posts

Posted - 2010-09-21 : 07:55:34
I have data I am trying to import via script however in the data itself there are single quotes, which is being interpreted as another input field (forgive me if my language is absolutely incorrect here) so there is a syntax error however I want the single quote to be there. is there a way to use single quotes without it being interpreted as one which is creating a syntax error?


for example if I have 455 mc'lane way I want the quote to be there but not interpreted as part of the sql statement, sortof like text only.

Sachin.Nand

2937 Posts

Posted - 2010-09-21 : 08:15:18

You can escape single quote using two single quotes.Something like this

declare @tbl as table(nm varchar(20))
insert into @tbl
select '455 mc''lane'

select * from @tbl




PBUH

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-09-21 : 08:39:05
Better understand on single quote

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

jar21

51 Posts

Posted - 2010-09-21 : 08:55:11
Thanks for the answer and noob guide :-)
Go to Top of Page
   

- Advertisement -