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)
 Issue with stuff function

Author  Topic 

atlachar123456
Starting Member

33 Posts

Posted - 2011-11-29 : 11:50:18
Hi,
Can any one corrrect my stuff function code..i want to get the output as 1','2','3','4;
actually i have used replace function its working in sql server but not in sybase insteadof replace i am using stuff function in sybase.

declare @text nvarchar(100)
set @text = '1,2,3,4'
select @text = ''''+ replace(@text,',',''',''')+''''
select @text


declare @text nvarchar(100)
set @text = '1,2,3,4'
select @text =''''+ STUFF(@text,PATINDEX(',',@text),CHAR_LENGTH(','),''',''') +''''
select @text


Post #1213334



atlaaaaaaaa

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-29 : 11:56:04
for sybase related help, please post it in some sybase forums. this is ms sql server forum

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

atlachar123456
Starting Member

33 Posts

Posted - 2011-11-29 : 12:37:54
Hello,
I am unable to find sybase forumns,can you please help me the code..

atlaaaaaaaa
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-29 : 12:41:50
quote:
Originally posted by atlachar123456

Hello,
I am unable to find sybase forumns,can you please help me the code..

atlaaaaaaaa


I dont have any knowledge on sysbase

try your luck at www.dbforums.com. it has a sybase forum

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

atlachar123456
Starting Member

33 Posts

Posted - 2011-11-29 : 14:13:57
ok,
select STUFF(@as_firmSelection,PATINDEX('%,%',@as_firmSelection),CHAR_LENGTH(@as_firmSelection),''',''')
when i run the above query for me its showing null...
this function will only replace the very first instance of the pattern that i am searching for

I need to have to write some code to find out the location of each of the commas (,) and replace them with (',')

If you have any knowlege on this ,will you please share with me..i will appreciate it

atlaaaaaaaa
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-30 : 01:33:47
quote:
Originally posted by atlachar123456

ok,
select STUFF(@as_firmSelection,PATINDEX('%,%',@as_firmSelection),CHAR_LENGTH(@as_firmSelection),''',''')
when i run the above query for me its showing null...
this function will only replace the very first instance of the pattern that i am searching for

I need to have to write some code to find out the location of each of the commas (,) and replace them with (',')

If you have any knowlege on this ,will you please share with me..i will appreciate it

atlaaaaaaaa


thats what replace does
otherwise you've use stuff over a loop

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -