Link to home
Start Free TrialLog in
Avatar of noobe1
noobe1

asked on

MSSQL Function To Split String

Hi Experts,
Can someone please post a function for MSSQL Server that splits the following string into integers:

300,400,900,1200

Thanks

Avatar of chapmandew
chapmandew
Flag of United States of America image

as 4 seperate fields?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of noobe1
noobe1

ASKER

As 4 integers separated by commas. Please refer to the attached code.

Thanks
ALTER PROCEDURE dbo.GetRadio
@StationList varchar(500)
 
AS
BEGIN
SELECT * FROM tblRadio
WHERE (tblRadio.StationID IN (@StationList))
END

Open in new window

Avatar of noobe1

ASKER

Lol....
You can leave them as you pass them in....just changed your proc a bit....

ALTER PROCEDURE dbo.GetRadio
@StationList varchar(500)
 
AS
BEGIN
declare @x varchar(2000)
set @x =
'SELECT * FROM tblRadio
WHERE (tblRadio.StationID IN ( ' + @StationList + '))'
exec sp_executesql @x
END
Sorry about that....must have submitted this as the answer was accepted.
That was very helpful thankyou!