vbnetcoder
asked on
stored procedure with IN
How would a where clause of a stored procedure with IN in the where clause where a list of parameter could be passed in??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Call the SP as follow:
EXEC sp_SPName '123,135,246,456'
If you expecting strings then you need to double quote them:EXEC sp_SPName ''ABC'',''DEF'',''GHI'''
ASKER
I attached my query any clue what is going wrong?
You forgot to attach it.
ASKER
When i call it like this:
Exec spFilmCertificate 'u' --- i get the error "Incorrect syntax near the keyword 'IN'."
When i call it like this
exec spFilmCertificate 'u' , 'p' -- i get the error "Procedure or function spFilmCertificate has too many arguments specified."
Exec spFilmCertificate 'u' --- i get the error "Incorrect syntax near the keyword 'IN'."
When i call it like this
exec spFilmCertificate 'u' , 'p' -- i get the error "Procedure or function spFilmCertificate has too many arguments specified."
ASKER
query attached
query.JPG
query.JPG
As I said before you need to double quote strings:
Exec spFilmCertificate '''u'''
exec spFilmCertificate '''u''' ,'''p'''
ASKER
That is giving me the same result.
I noticed that the query i uploaded is showing in red ..perhaps i am doing something wrong?
I noticed that the query i uploaded is showing in red ..perhaps i am doing something wrong?
Must be some missing single quote. In your stored procedure instead of executing the query, print it so we can see what's wrong:
'--EXEC sp_executesql @MySelect
PRINT @MySelect
ASKER
When i run this: Exec spFilmCertificate '''u'''
I get this
SELECT dbo.tblFilm.FilmName, dbo.tblCertificate.Certifi cateName, CertificateID
FROM dbo.tblFilm INNER JOIN
dbo.tblCertificate ON dbo.tblFilm.FilmCertificat eID = dbo.tblCertificate.Certifi cateID
Where CertificateID = IN ('u')
------------
When i run this: exec spFilmCertificate '''u''' ,'''p'''
I get the error Msg 8144, Level 16, State 2, Procedure spFilmCertificate, Line 0
Procedure or function spFilmCertificate has too many arguments specified.
I get this
SELECT dbo.tblFilm.FilmName, dbo.tblCertificate.Certifi
FROM dbo.tblFilm INNER JOIN
dbo.tblCertificate ON dbo.tblFilm.FilmCertificat
Where CertificateID = IN ('u')
------------
When i run this: exec spFilmCertificate '''u''' ,'''p'''
I get the error Msg 8144, Level 16, State 2, Procedure spFilmCertificate, Line 0
Procedure or function spFilmCertificate has too many arguments specified.
Yes, like I told you before. You are passing 2 parameters ('u' and 'p') and you should only pass one as a single string (I removed the extra single quotes near the comma):
exec spFilmCertificate '''u'' ,''p'''
ASKER
Got it ... thanks
ASKER
ty
ASKER