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 insert a comma in the string?

Author  Topic 

ConKi
Starting Member

2 Posts

Posted - 2010-03-23 : 11:51:06
Good morning,
Could any one show me how to insert a comma in a string of 10 characters at position 2?
Thank you so much,
ConKi

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-03-23 : 11:55:12
Lots of ways.

Here's an example using STUFF

Check the help installed with sql server -- it's really good -- just go to HELP -> INDEX in management studio and search for STUFF

DECLARE @foo VARCHAR(255)
SET @foo = 'asd;aksf;kasdg'

SELECT @foo

SELECT STUFF(@foo, 3, 0, ',')



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-03-23 : 11:56:28
[code]select stuff(<urcolumn>,2,0,',') from <urtable>[/code]
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-03-23 : 11:57:01
Go to Top of Page

ConKi
Starting Member

2 Posts

Posted - 2010-03-23 : 12:00:51
Thank you so much. It worked.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-25 : 03:38:12
quote:
Originally posted by ConKi

Thank you so much. It worked.


Both the solutions are not same
Which one worked?

Madhivanan

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

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-03-25 : 05:10:59
The only difference is that my one will insert immediately after the second character and vijayisonly's one will insert immediately after the first.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -