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
 Problem with functions

Author  Topic 

xlncsql
Starting Member

3 Posts

Posted - 2010-03-06 : 11:34:13
HI here the function I have created to split the string ex:'m1,m2,m3'
to be splitted as m1,m2,m3. I have sucessfully created function but when use the function with a string it gives me NUll o/p can you guyz help me out with it

create function fun_split
(
@string varchar(20)
)
RETURNS char(5)
begin
declare @b int,@c varchar(5), @d varchar(5)
set @d = replace('@string',',','.')
set @b=0
while(@b<4)
begin
set @c=parsename(@d,@b)
set @b=@b+1
return (@c)
end
end
SELECT DBO.fun_split('M1,M2')
Gives me null O/P if this not right way doing can you explane me y?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-06 : 12:21:07
replace('@string',',','.')
replace(@string,',','.')



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

xlncsql
Starting Member

3 Posts

Posted - 2010-03-06 : 21:57:08
I did dat too stillit returns me null.I guess I am using sclar functions so I made use of TVF table value function so here is my code

alter function fun_split1
(
@string varchar(20)
)
RETURNS @tab table
(
t varchar(10)
)
as
begin
declare @b int,
@c varchar(10),
@d varchar(10),
@x varchar(10)
insert @tab
select @c
set @d = replace(@string,',','.')
set @b=len(@d)
while(@b<4)
begin
set @c=parsename(@d,@b)
set @b=@b+1
end
return
end

can you identtifie mistakes in this
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-07 : 02:18:45
see this

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

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

Go to Top of Page
   

- Advertisement -