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
 General SQL Server Forums
 New to SQL Server Programming
 how to escape comma from select statement

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2011-03-23 : 11:56:04
how to escape comma from select statement?

qutesanju
Posting Yak Master

193 Posts

Posted - 2011-03-23 : 11:59:21
my statement is like

select name from temp

here temp table contains column with comma

like
'john,mathues'
'nishu,mathues'

so how to select this
Go to Top of Page

qutesanju
Posting Yak Master

193 Posts

Posted - 2011-03-23 : 12:11:08


My column name is like 'john,mathues','nishu*baby'
and 'john,mathues','nishu*baby' these are not the values.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-03-23 : 12:15:55
Many people here will tell you that it was a bad idea to put last name and first name together in a single column, and they would be right. But I won't dwell on that :--)

What do you want your output to look like?
john mathues
or mathuses
or john
or something else?

If you just want to get rid of the comma, and get "john mathues" do this
select replace(YourColumn,',',' ') from YourTable
But, that will get rid of ANY comma, for example if the name were "john,mathuses, III" you will lose both commas.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-03-23 : 12:46:18
quote:
Originally posted by qutesanju



My column name is like 'john,mathues','nishu*baby'
and 'john,mathues','nishu*baby' these are not the values.


You should really conform your column names to Regular Identifiers (look in Books Online for: Rules for Regular Identifiers). Since you have already broken those rules, you can use a delimited identifier. SQL Server uses double-quotes ("") and square-brackets ([]) to denote a delimited identifier. For example: [john,mathues], [nishu*baby]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-24 : 04:28:17
You are having column names that are supposed to be column values

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

qutesanju
Posting Yak Master

193 Posts

Posted - 2011-03-24 : 04:51:24
The column names are generated dynamically using front end application
Go to Top of Page
   

- Advertisement -