Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

stored procedure and "IN" statement

Posted on 2001-08-13
2
Medium Priority
?
217 Views
Last Modified: 2009-07-29
I'm trying to do a stored procedure which include a WHERE clause using a "IN" statement.  How can I provide value to this "IN" statement using a parameter.

ie. sp_pendingsubmission 'form1', '1,2'


CREATE PROCEDURE sp_pendingsubmission
@sSubmissionForm_Id  varchar(20),
@sPartner_ID varchar(20)
AS


SELECT submission_ID, result_value
FROM tbl_result
WHERE
(submissionForm_ID = @sSubmissionForm_Id) AND
(section_ID = 'projectinfo') AND
(question_ID = 'projecttitle') AND
(submission_ID IN
     (SELECT submission_ID
       FROM tbl_result
       WHERE
     (submissionForm_ID = @sSubmissionForm_Id) AND
     (
     ((section_ID = 'partneradmin') AND
     (question_ID = 'statusid') AND
     (result_value = 'pending'))
     OR
     ((section_ID = 'gbl') AND
     (question_ID = 'partnerid') AND
     (result_value in  (@sPartner_ID)))
     )
      GROUP BY submission_ID
     HAVING COUNT(submission_ID) >= 2))
0
Comment
Question by:martalex
2 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6382935
replace
(result_value in  (@sPartner_ID))
by
(',' + @sPartner_ID  +',' + like '%,'+ result_value + ',%')

CHeers
0
 
LVL 39

Accepted Solution

by:
appari earned 200 total points
ID: 6382965
CREATE PROCEDURE sp_pendingsubmission
@sSubmissionForm_Id  varchar(20),
@sPartner_ID varchar(20)
AS


exec( " SELECT submission_ID, result_value
       FROM tbl_result WHERE
      (submissionForm_ID = @sSubmissionForm_Id) AND
      (section_ID = 'projectinfo') AND
      (question_ID = 'projecttitle') AND
      (submission_ID IN
     (SELECT submission_ID
      FROM tbl_result
      WHERE
    (submissionForm_ID = @sSubmissionForm_Id) AND
    (
    ((section_ID = 'partneradmin') AND
    (question_ID = 'statusid') AND
    (result_value = 'pending'))
    OR
    ((section_ID = 'gbl') AND
    (question_ID = 'partnerid') AND
    (result_value in  (" + @sPartner_ID + ")))
    )
     GROUP BY submission_ID")

   
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question