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 2008 Forums
 Transact-SQL (2008)
 assign

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-01-17 : 11:55:36
how can I place apostrophe around texts?
i.e.
declare @values varchar(100)

set @values = 'EUR, USD, GBP'

I would like them to be:
set @values = 'EUR', 'USD', 'GBP'

Thanks

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-17 : 12:10:07
declare @values varchar(100)
set @values = '''EUR'', ''USD'', ''GBP'''
SELECT @values


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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-01-17 : 12:22:03
quote:
Originally posted by X002548

declare @values varchar(100)
set @values = '''EUR'', ''USD'', ''GBP'''
SELECT @values


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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/





May be I should have elaborated further.
the @values can vary...
Let's say @values = 'EUR, GBP, JPY'
I would like to see:
@values to be ('EUR', 'GBP', 'JPY')
Thanks
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-01-17 : 12:25:18
How about this:
declare @values varchar(1000)
set @values = 'USD, GBP, JPY'

set @values = '(' + replace(@values, ', ', ''', ''') + ')'
set @values = replace(@values, '(', '(''')
set @values = replace(@values, ')', ''')')

print @values
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-17 : 12:30:10
You can also use CHAR(39), for example:
declare @values varchar(1000)
set @values = 'USD, GBP, JPY'

set @values = '(' + CHAR(39) + replace(@values, ', ', CHAR(39) + ', ' + CHAR(39)) + CHAR(39) + ')'
print @values
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-17 : 13:30:26
WHY BTW???
So you can Do WHERE COl IN @values?

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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-01-18 : 02:44:32
Thank you
Go to Top of Page
   

- Advertisement -