?
Solved

stored procedure and "IN" statement

Posted on 2001-08-13
2
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

718 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