Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,,
I need to pass the splitted string as a parameter in SQL Stored Procedure please find the exact solu....Below i've my Sp please guide me to achieve my solution...
Hi in my table i have an column called complexion where i've the data as 2,5, i am getting two and 5 seperately i need to pass thw value of 2 nad 5 and i should get the two rows in my dataset...but i am getting two rows with both values as 2,5, only not as 2 & 5 seperately
[CODE]
SQL
DECLARE @Test VARCHAR(1000), @RecSet VARCHAR(500), @ID VARCHAR(10), @Value VARCHAR(60)

DECLARE @StartingPos INT,@RecPos INT

SET @StartingPos= 1

SET @Test =(select cmp.complexion1 from customerexpectation cmp where cmp.customerid='68572b93-16bd-4764-b75f-3aad35fef04b')

WHILE @StartingPos<=LEN(@Test)

BEGIN

    SELECT @RecPos = CHARINDEX(',',@Test,@StartingPos)

    SELECT @RecSet=SUBSTRING(@Test,@StartingPos,@RecPos-@StartingPos)
    
	PRINT @RecSet

	SELECT CC.CUSTOMERID,CC.COMPLEXION1,CM.ID FROM CUSTOMEREXPECTATION CC
	LEFT OUTER JOIN
	COMPLEXION CM
	ON CC.COMPLEXION1=@RecSet	WHERE CUSTOMERID='68572b93-16bd-4764-b75f-3aad35fef04b'

	SELECT @StartingPos=@RecPos+1

END[/CODE] 
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900