July 14, 2013 at 3:40 pm
Hi there,
I'm new to SQL and to Crystal reports. I know that to pass a multiple value parameter to a stored procedure in SQL I need to arrange it into a comma delimited string. I've done that with Crystals join command but I'm having trouble understanding how to split the comma delimited parameter so I can use it in a where IN clause or an If statement (which ever is better). I want this procedure to do the same thing for 3 of the values in the parameter and nothing for the rest of them.
My code so far is below:
Thanks for any suggestions!
create PROCEDURE PeopleHistory @Para1 VARCHAR(20), @Para2 VARCHAR(20) as
IF (@Para2 = 'Old’)
select People.FirstName, People.LastName, Company.Title, Experience.Title from People
LEFT JOIN Experience ON People.ID = Experience.PeopleID
LEFT JOIN Company ON Experience.CompanyID = Company.ID
WHERE People.ID = @Para1
EXCEPT
select People.FirstName, People.LastName, Company.Title, Experience.Title from People
LEFT JOIN Experience ON People.CurrentExperienceID = Experience.ID
LEFT JOIN Company ON Experience.CompanyID = Company.ID
WHERE People.ID = @Para1
ELSE IF (@Para2 = ‘Unkown')
select People.FirstName, People.LastName, Company.Title, Experience.Title from People
LEFT JOIN Experience ON People.ID = Experience.PeopleID
LEFT JOIN Company ON Experience.CompanyID = Company.ID
WHERE People.ID = @Para1
EXCEPT
select People.FirstName, People.LastName, Company.Title, Experience.Title from People
LEFT JOIN Experience ON People.CurrentExperienceID = Experience.ID
LEFT JOIN Company ON Experience.CompanyID = Company.ID
WHERE People.ID = @Para1
ELSE IF (@Para2 = ‘unkown2’)
select People.FirstName, People.LastName, Company.Title, Experience.Title from People
LEFT JOIN Experience ON People.ID = Experience.PeopleID
LEFT JOIN Company ON Experience.CompanyID = Company.ID
WHERE People.ID = @Para1
EXCEPT
select People.FirstName, People.LastName, Company.Title, Experience.Title from People
LEFT JOIN Experience ON People.CurrentExperienceID = Experience.ID
LEFT JOIN Company ON Experience.CompanyID = Company.ID
WHERE People.ID = @Para1
ELSE IF (@Para2 is null)
Do Nothing
July 14, 2013 at 3:54 pm
Does this article helps you?
July 14, 2013 at 4:14 pm
Luis Cazares (7/14/2013)
Does this article helps you?
Thank you Luis!
I'm not sure if it does. I understand the logic but my parameter won't have the '1st comma' and I'm not 100% sure how I use this to then run my clauses against.
July 14, 2013 at 4:31 pm
You could as well try to use the 8k Splitter presented here.
http://www.sqlservercentral.com/articles/Tally+Table/72993/
It will return you a table from which you can do a join or semi-join (IN or EXISTS). 😉
July 15, 2013 at 3:51 pm
Luis Cazares (7/14/2013)
You could as well try to use the 8k Splitter presented here.http://www.sqlservercentral.com/articles/Tally+Table/72993/
It will return you a table from which you can do a join or semi-join (IN or EXISTS). 😉
Got it working! Took me a bit to realize that I just had to copy/paste the tally code and then call it as a function but I got it! Awesome stuff, thank you Luis!
July 15, 2013 at 4:21 pm
I'm glad I could help. It might not have been possible without the great articles from Jeff. 🙂
July 15, 2013 at 10:17 pm
Luis Cazares (7/15/2013)
I'm glad I could help. It might not have been possible without the great articles from Jeff. 🙂
You're too kind. :blush: Thanks, Luis.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 16, 2013 at 5:45 am
Jeff Moden (7/15/2013)
Luis Cazares (7/15/2013)
I'm glad I could help. It might not have been possible without the great articles from Jeff. 🙂You're too kind. :blush: Thanks, Luis.
Thank you Jeff!
July 16, 2013 at 7:30 am
LegoAddict (7/16/2013)
Jeff Moden (7/15/2013)
Luis Cazares (7/15/2013)
I'm glad I could help. It might not have been possible without the great articles from Jeff. 🙂You're too kind. :blush: Thanks, Luis.
Thank you Jeff!
No problem and thank you for the feedback. Glad the article helped and that you got your problem solved.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply