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)
 how to include a literal '

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-07 : 10:57:45
#t1:
name
jeff
bob

select txt='insert into #b values ('
+name
+')'
from #t1

this code generate:
insert into #b values (jeff)
insert into #b values (bob)


but I want get
insert into #b values ('jeff')
insert into #b values ('bob')

How can I show the real "'" in the resulting string ?
Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-11-07 : 11:00:29
[code]select txt='insert into #b values ('''
+name
+''')'
from #t1[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-11-07 : 12:18:51
or

select txt='insert into #b values ('
+ char(39)
+ name
+ char(39)
+ ')'
from #t1

if you prefer that

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-07 : 12:25:33
You guys funny

INSERT INTO #b ([Name]) SELECT [Name] FROM #t1




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-11-07 : 12:35:51
Yeah, but its making a script that the OP can put on a CD and take to their server on Mars ...
Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-07 : 14:09:22
Thanks, Guys.
Go to Top of Page
   

- Advertisement -