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
Can someone please post a function for MSSQL Server that splits the following string into integers:
300,400,900,1200
Thanks
as 4 seperate fields?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As 4 integers separated by commas. Please refer to the attached code.
Thanks
Thanks
ALTER PROCEDURE dbo.GetRadio
@StationList varchar(500)
AS
BEGIN
SELECT * FROM tblRadio
WHERE (tblRadio.StationID IN (@StationList))
END
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
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!