Hi
I recommend create a nice function on your database.
CREATE FUNCTION [dbo].[getParmsFromString]
(@String VARCHAR(MAX))
RETURNS @Parms TABLE
(
Token VARCHAR(MAX)
)
AS
BEGIN
IF CHARINDEX(',', @String) != 0
BEGIN
;WITH cte0(Token, List) AS
(
SELECT SUBSTRING(@String, 1, CHARINDEX(',',@String,1) - 1)
,SUBSTRING(@String,CHARINDEX(',',@String,1) + 1, LEN(@String)) + ','
UNION ALL
SELECT SUBSTRING(List,1,ISNULL(CHARINDEX(',',List,1) - 1,1))
,SUBSTRING(List,CHARINDEX(',',List,1) + 1, LEN(List))
FROM cte0
WHERE LEN(cte0.List) > 0
)
INSERT INTO @Parms (Token)
SELECT Token
FROM cte0
OPTION (MAXRECURSION 0)
RETURN;
END
ELSE
INSERT INTO @Parms
SELECT @String
RETURN;
END
GO
To use this function all you need to do is call it and parse the Paramater value.
The return of this function will give you a table with each Currency in the Paramater value as a single row.
For example
String1 = 'Dollar'
String2 = '1,2,3,4,5'
select * from dbo.getParmsFromString(String1) will result in
Dollar
select * from dbo.getParmsFromString(String2 ) will result in
1
2
3
4
5
Hope this will help you solve your problem.
--------------------------------------------------------------------------------------------------------------------------------------------------------
To some it may look best but to others it might be the worst, but then again to some it might be the worst but to others the best.
http://www.sql-sa.co.za