Solved

stored procedure and "IN" statement

Posted on 2001-08-13
2
183 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 142

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 50 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

803 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