Passing multi-value parameter in stored procedure ssrs

I have  customer parameter which is a drop down list in my report and I have set it to "allow multiple values". This is an SSRS report.
How do I pass multiple values to my stored procedure?
RJ

Hi ,
Create a Table valued function in SQL Functions  as below 
Step 1
CREATE FUNCTION [dbo].[FnSplit]
@List nvarchar(2000),
@SplitOn nvarchar(5)
RETURNS @RtnValue table 
Id int identity(1,1),
Value nvarchar(100)
AS  
BEGIN
While (Charindex(@SplitOn,@List)>0)
Begin 
Insert Into @RtnValue (value)
Select
Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1))) 
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
End 
Insert Into @RtnValue (Value)
Select Value = ltrim(rtrim(@List))
Return
END
Step 2 in your store procedure change the parameter where condition something like below
ALTER PROCEDURE [dbo].[SomeSP] 
-- Add the parameters for the stored procedure here
@CostCentre NVARCHAR(255)
SELECT
[ProjectCode],[ProjectName],[ProjectManager],SUM([Hours]) AS [Hours MTD]FROM dbo.Rpt_NRMA_CATS NC
INNER JOIN PeriodID P ON NC.PeriodID=P.PeriodID
WHERE 
([CostCentre]) collate database_default IN(SELECT Value FROM dbo.FnSplit(@CostCentre,','))
END
I hope this will help you.
Dasari

Similar Messages

  • Passing multi-value parameter from BIEE dashboard to BIP report

    It is possibile passing multi-value parameter from BIEE dashboard prompt to BI Publisher integrated report? (BIP report has a DB data source (not a answers))
    Thank you
    R.

    Hi Rajkm,
    In order to pass a multi-value parameter through the Reporting Services Web services, you need to define the same numbers of ParameterValue objects as the number of the values of the multi-value parameter being past into the report. The Name property
    of these ParameterValue objects must be specified same to the parameter name.
    I found a good FAQ article for this scenario:
    How do I pass a multi-value parameter into a report with Reporting Services Web service API?:
    http://blogs.msdn.com/b/sqlforum/archive/2010/12/21/faq-how-do-i-pass-a-multi-value-parameter-into-a-report-with-sql-server-reporting-services-ssrs-web-services-api.aspx
    Hope this helps.
    Elvis Long
    TechNet Community Support

  • Passing multi value parameter to the Drill through report

    Hi
    I have two reports say Report A and Report B.
    Both reports using same parameters.
    I am Navigating from Report A to Report B using Jump to Report option.
    Now when I pass multiple parameter to the Report B it only displays first parameter results.
    In report B I have parameter multi value select to true.
    I would like to know if its possible or not to pass multi value parameter in drill through report?
    I would appreciate if someone can help me here.
    Regards
    Amit

    Yes you can pass multi value parameters to a drill through report.
    It works similar to multi value parameters for subreports, which is discussed in detail in this thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=163803&SiteID=1
    -- Robert

  • Pass a date parameter to Stored Procedure

    Hello friends,
    Can you help to pass a date parameter to Stored procedure from JSP. This is my code:
    In Oracle 9i I have this:
    PROCEDURE SP_EDORES(
    pfechaini IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    pfechafin IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    p_recordset OUT PKG_REP_CIERRE.cursor_type) AS
    In JSP have this:
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setDate(1,Date.valueOf("01-06-2005"));
    stmt.setDate(2,Date.valueOf("30-06-2005"));
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    <TR>
    <TD ALIGN=CENTER> <%= rset.getString(1) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(2) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(3) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getInt(4) %> </TD>
    </TR>
    <%
    The Stored Procedure returns de Result set, however I think does not recognized the date format because I need it with this format dd-mm-yyyy.
    Thanks in advance

    to use Date you will need the oracle package.
    u can try this other solution: use String, not Date
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setString(1,"01-06-2005");
    stmt.setString(2,"30-06-2005");
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    if this don't work you can change your PL/SQL to get Strings and do the conversion with TO_DATE in the sql statement.

  • Passing Multi-Value Parameter to a Stored Procedure

    Has anyone experienced passing a Parameter (MultiValue) to a Stored Procedure? I am aware that Crystal Passes the Param as an Array. How would you go about handling this within a Stored Procedure???

    Hi Daniel
    Try as below:
    1. Create a Crystal report, and add a multi-value parameter.
    2. Since the multi-value parameter is treated as an array, create a formula that uses the JOIN function. Create a formula as below:
    //Formula: @JoinFormula
    Join ({?Multi-value parameter array},";")
    ====================
    NOTE:
    In the formula above, a semi-colon (";") is the delimiter.
    ====================
    3. Within the main report, create a subreport based on the stored procedure, and include the parameter to be populated with the multi-value list.
    4. Link the Join formula in the main report to the stored procedure parameter in the subreport.
    Doing so passes a multi-value parameter to the stored procedure.
    Hope this helps!!!!
    Regards
    Sourashree

  • Would like to pass multi-value parameter to a stored procedure

    Hi,
    Is it possible to pass a multi-value parameter to a stored procedure using crystal reports.
    Is there is a way to do so??/
    Thanks,
    Brian.

    Hi,
    Is it that you want to pass 2 or more parameters to a stored proc. it is possible
    go to database expert
    select your connection and click on add command their you will have to create parameters and pass to a proc
    for ref..
    {CALL `menagerie`.`sp_timer`({?delay time},{?delay time2})}
    where `menagerie`.`sp_timer` is a stored proc.
    and delay time and delay time2 are  parameters.
    but if it is like you have to pass multiple values to stored proc using single parameter as per my experience its
    not possible.

  • OpenDocument.aspx - pass multi value parameter when report type is actx

    We are running Crystal Reports XI R2 against a business objects infoview server.
    We have been successfully using the OpenDocuments method for opening crystal reports but have run into a snag.  When using a multi-value parameter, we can only get it to work when the viewer is set to HTML.  Setting to ActiveX prompts us to enter in the parameter values manually.
    This address works (using sViewer=HTML):
    http://vsx2af0x/businessobjects/enterprise115/infoview/scripts/opendocument.aspx?sType=rpt&sViewer=html&lsMpSiteIDs=[1235880],[1235891],[1235902],[1235913]&sPath=[Development][CGIS][Intranet Mapping][COS_Base]&sDocName=DetailedSite&sRefresh=Y
    This address does not work (using sVIewer=actx):
    http://vsx2af0x/businessobjects/enterprise115/infoview/scripts/opendocument.aspx?sType=rpt&sViewer=actx&lsMpSiteIDs=[1235880],[1235891],[1235902],[1235913]&sPath=[Development][CGIS][Intranet Mapping][COS_Base]&sDocName=DetailedSite&sRefresh=Y
    Any thoughts on the problem?

    As I understand what you need is to use LookupSet function. 
    Suppose if your dataset is like this (for simplicity I'm showing only required fields)
    PersonID Project Company
    ID1 P1 C1
    ID1 P2 C1
    ID1 P3 C2
    ID1 P4 C2
    ID1 P5 C3
    If you want to get the full project list for the person just send the PersonID alone and filter using it in the subreport. You can keep the project/company parameters optional in that case and put a default value. This would be the easiest thing.
    Now if you want pass the project parameter also you need to pass it like this
    =Join(LookupSet(Fields!Person.Value,Fields!Person.Value,Fields!Project.Value,"DatasetName"),",")
     This would act like a self lookup and return you full list of projects for the person and then you can use this to set the parameter value in the subreport.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Pass multi value parameter to sub report in Drill through report, ssrs

    I have two reports 1 is subreport and other is main report. Date Field are placed in both reports. i have groups in main report,
    one group is task. In the task fields one persons is working in 3 project, two project are same company and 1 is for other and it give me count for each project. I
    want when i click on link it send multivalue parameter to subreport and it just show matching records.
    Asif Mehmood

    As I understand what you need is to use LookupSet function. 
    Suppose if your dataset is like this (for simplicity I'm showing only required fields)
    PersonID Project Company
    ID1 P1 C1
    ID1 P2 C1
    ID1 P3 C2
    ID1 P4 C2
    ID1 P5 C3
    If you want to get the full project list for the person just send the PersonID alone and filter using it in the subreport. You can keep the project/company parameters optional in that case and put a default value. This would be the easiest thing.
    Now if you want pass the project parameter also you need to pass it like this
    =Join(LookupSet(Fields!Person.Value,Fields!Person.Value,Fields!Project.Value,"DatasetName"),",")
     This would act like a self lookup and return you full list of projects for the person and then you can use this to set the parameter value in the subreport.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Passing multiple values to a stored procedure

    Hi All,
    I have a stored procedure which displays a chart. The header of this procedure is:
    create or replace procedure chart ( p_period IN VARCHAR2) is
    When calling this procedure with something like the folloeing:
    <PARAM NAME=movie VALUE="/i/charts.swf?library_path=/i/charts_library&xml_source=ohsinit.chart?p_period=MONTH">
    everything works OK.
    Now, I would like to replace p_period=MONTH with a value coming from an ITEM on the page, so something like:
    <PARAM NAME=movie VALUE="/i/charts.swf?library_path=/i/charts_library&xml_source=ohsinit.chart?p_period=:P13_PERIOD">
    However, the above doesn't work.
    Can anyone give me the correct syntax please?
    Also what would be the syntax for passing more than one value? ie:
    source=ohsinit.chart?p_period=:P13_PERIOD,p_start=:P13_START_DATE ?
    Regards,
    Pawel.

    Hi Denes,
    I am not sure I understand your post...
    What I am trying to do here is to pass 3 values namely
    P13_PERIOD (VARCHAR2),
    P13_START_DATE (DATE),
    P13_END_DATE (DATE)
    into a stored procedure which displays the graph.
    So far I managed to get it working using:
    <PARAM NAME=movie VALUE="/i/charts.swf?library_path=/i/charts_library&xml_source=ohsinit.chart?p_period=&P13_PERIOD.">
    However when I try to put in:
    <PARAM NAME=movie VALUE="/i/charts.swf?library_path=/i/charts_library&xml_source=ohsinit.chart?p_period=&P13_PERIOD.,p_start=&P13_START_DATE.">
    I get the graph blank (but not the orange timeout message... if you are familiar with XML/SWG graphs.)

  • Passing Dynamic Values to a Stored Procedure

    I have a stored procedure to create a Table. How to I pass a
    value to the procedure to name the Table. This SP works except the
    name of the table is @newcomm not the value I am trying to pass in.
    What is the proper syntax to make this happen.
    CREATE PROCEDURE [dbo].[sp_newcommenttbl]
    @newcomm varchar (50)
    AS
    BEGIN
    CREATE TABLE [dbo].[@newcomm] (
    [configid] [int] IDENTITY (1, 1) NOT NULL ,
    [email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
    NULL ,
    [adminemail] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [erroremail] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [toCommentFormEmail] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dsn] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
    NULL ,
    [gmdsn] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
    NULL ,
    [dbusername] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbpassword] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [acfcpath] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [acfcpath2] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [acfcpath3] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [urlactivate] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [urlresetpassword] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [initialized] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename1] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename2] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename3] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename4] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename5] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename6] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename7] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename8] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename9] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename10] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [pageheader] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL
    ) ON [PRIMARY]
    END
    GO
    <cfstoredproc procedure="sp_newcommenttbl"
    datasource="xxxxx" returncode="no">
    <cfprocparam type="in" maxlength="50"
    cfsqltype="cf_sql_varchar" value="pighg3">
    </cfstoredproc>

    When I create the procedure I don't get an error. I get an
    error when I call it.
    [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect
    syntax near the keyword 'ON'.
    ColdFusion cannot determine the line of the template that
    caused this error. This is often caused by an error in the
    exception handling subsystem.
    Here is the call.
    <cfstoredproc procedure="sp_newcommenttbl"
    datasource="pisecurity" returncode="no">
    <cfprocparam type="in" maxlength="50"
    cfsqltype="cf_sql_varchar" value="pighg3" variable="newcomm">
    </cfstoredproc>
    Here is the syntax for the SP.
    CREATE PROCEDURE [dbo].[sp_newcommenttbl]
    @newcomm varchar (50)
    AS
    BEGIN
    EXEC('CREATE TABLE [dbo].['+@newcomm+'] (
    [configid] [int] IDENTITY (1, 1) NOT NULL ,
    [email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
    NULL ,
    [adminemail] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [erroremail] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [toCommentFormEmail] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dsn] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
    NULL ,
    [gmdsn] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
    NULL ,
    [dbusername] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbpassword] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [acfcpath] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [acfcpath2] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [acfcpath3] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [urlactivate] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [urlresetpassword] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [initialized] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename1] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename2] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename3] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename4] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename5] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename6] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename7] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename8] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename9] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [dbtablename10] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL ,
    [pageheader] [varchar] (50) COLLATE
    SQL_Latin1_General_CP1_CI_AS NULL
    ON [PRIMARY]')
    END
    GO

  • Pass Multi-value Parameter from Web Page

    SSRS 2012 Sp1
    Developed reports working fine. They includes some cascading parameters behaviour: it means: select Parameter1, then the values are passed to the parameter2, then the selected value (parameter2) are passed to Parameter 3 and so on.
    The reports in SSRS portal work fine.
    Now, the clients want to run the reports from a custom web page (It is not reporting services).
    in this case the user press a button and automatically the web page retrieve the data to be passed to the report.
    Here the problem: although the value passed are correct, the report is not executed! Instead, the report opens waiting for user action (as if the paramters1, 2, 3 ... must be selected).
    Please, do you know how to run a SSRS report from a <Custom> web page by passing the parameters?
    Thanks for your help

    in that case you should be passing default values for the parameters in the report and url used should be report viewer url rather than report manager url
    Another way is using report viewer
    see
    http://cybarlab.com/call-ssrs-report-in-asp-net-project
    http://bhushan.extreme-advice.com/call-ssrs-report-with-prameters-from-asp-net-web-application/
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Passing multi-value parameter to a transaction iView

    Hi all,
    Here is my problem, I try to feed a selection-option (multi value) from the "DynamicParameter" section of the url.
    For example I use this URL, to feed the select-options with A, B and C:
    http://XXX:51000/irj/portal/test?DynamicParameter=S_opt-LOW=A;S_opt-LOW=B;S_opt-LOW=C
    But I only get the last value.
    Is it possible to load multi values in a selection option from the url ?
    How?
    Let me know.
    Thanks.
    Judicael

    Hi Judicael,
    The dynamic parameter must be URL encoded.
    http://XXX:51000/irj/portal/test?DynamicParameter=S_opt-LOW%3DA%26S_opt-LOW%3DB%26S_opt-LOW%3DC
    %3D is the URL-encoding for "=" and %26 is the encoding for "&"
    http://help.sap.com/saphelp_nw2004s/helpdata/en/44/be65751c743959e10000000a1553f6/content.htm
    Regards,
    Min

  • Passing parameter into stored procedure

    Hi guys,
    I have a big problem here passing as a parameter in stored
    procedure.
    If i pass as a parameter in where clause it is working fine.
    Whenever i pass the parameter in order by it was not working..
    How to implement this issue????
    Here i am giving the example for package:
    PACKAGE XTRA.TEST_STATUS
    AS
    TYPE GenericCurTyp IS REF CURSOR;
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2,GENERAL_CUR IN OUT GenericCurTyp);
    END TEST_STATUS;
    PACKAGE BODY XTRA.TEST_STATUS
    AS
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2, GENERAL_CUR IN OUT GenericCurTyp
    ) AS
    BEGIN
    OPEN GENERAL_CUR FOR
    select last_name,first_name from applicant Order By insortgroup;
    END SP_MAIN;
    END TEST_STATUS;
    Passing as a parameter i am getting the below details.
    LAST_NAME FIRST_NAME
    ASFSDAF DASDFASF
    Ad DASD
    Adams John
    DANA WITEST
    If i hot code the parameter insortgroup to last_name
    i am getting the below values:
    LAST_NAME FIRST_NAME
    'ANNUNZIO GIANCOLA GABRIEL
    0'BRIEN ARMA
    0120453EZ ESTANISLAO
    082479 ELIZABETH
    Thanks,
    Rao

    CREATE OR REPLACE PACKAGE xtra.test_status
    AS
      TYPE GenericCurTyp IS REF CURSOR;
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp);
    END test_status;
    CREATE OR REPLACE PACKAGE BODY xtra.test_status
    AS
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp)
      AS
        select_statement VARCHAR2 (4000) := NULL;
      BEGIN
        select_statement :=
        'SELECT   last_name,
                  first_name
         FROM     applicant
         ORDER BY ' || insortgroup;
        DBMS_OUTPUT.PUT_LINE (select_statement);
        OPEN general_cur FOR select_statement;
      END sp_main;
    END test_status;

  • Passing Comma separated input to stored procedure in IN clause

    Hi All,
    I have a query below in a stored procedure as like this
    Create PROCEDURE insertinfo
    @userids varchar(MAX)
    AS
    BEGIN
    INSERT INTO records
    (id
    ,name
    ,address1
    ,address2
    ,pincode
    SELECT
    id,
    name,
    addr1,
    addr2,
    pin,
    FROM userinfo
    WHERE userinfo.id in(@userids)
    END
    I am not using any dynamic sql. Its a simple insert into select query with multiple parameters supplied via thd @userids parameter. When i  run the query nothing is inserting in the "records" table. I have gone throught the web search have
    tried with few options but no result yet. The query works fine when i pass only a single value, but it does not work when is pass multiple values.
    Please guide on this.
    Your help is appreciated.
    Thanks,
    mds2907

    mds2907,
    CHeck this:
    --Method 1
    --Usage of TVP
    --Method 2
    --Usage of SPLIT fn()
    Create PROCEDURE insertinfo(@userids varchar(MAX))
    AS
    BEGIN
    INSERT INTO records
    (id,name,address1,address2,pincode)
    SELECT id, name,addr1,addr2, pin
    FROM userinfo
    WHERE userinfo.id in(select * from sample_split(@userids,','))
    END
    --Method3
    --Usage of Dynamic SQL
    Applicable only when the values in csv are integers
    like '1,2,3'
    Create PROCEDURE insertinfo(@userids varchar(MAX))
    AS
    BEGIN
    DECLARE @sql nvarchar(max)
    SET @sql='
    INSERT INTO records
    (id,name,address1,address2,pincode)
    SELECT id, name,addr1,addr2, pin
    FROM userinfo
    WHERE userinfo.id in('+@userids')'
    EXEC sp_executesql @sql
    END
    Sample_Split():
    CREATE FUNCTION dbo.sample_Split
    @RowData nvarchar(2000),
    @SplitOn nvarchar(5)
    RETURNS @RtnValue table
    Id int identity(1,1),
    Data nvarchar(100)
    AS
    BEGIN
    Declare @Cnt int
    Set @Cnt = 1
    While (Charindex(@SplitOn,@RowData)>0)
    Begin
    Insert Into @RtnValue (data)
    Select
    Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
    Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
    Set @Cnt = @Cnt + 1
    End
    Insert Into @RtnValue (data)
    Select Data = ltrim(rtrim(@RowData))
    Return
    END
    Usage of TVP for a scenario similar to yours is explained herE:
    http://blog.sqlauthority.com/2008/08/31/sql-server-table-valued-parameters-in-sql-server-2008/
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/0ead7ceb-3fdd-4625-aa82-1d4195f984b1/passing-multivalue-parameter-in-stored-procedure-ssrs
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • URGENT: I want to pass a variable to a stored procedure at run time

    Post Author: aruplabs
    CA Forum: Data Connectivity and SQL
    I work for a health care provider and I have reports that pull PHI (Protected Health Information) about patients that needs to be logged according to federal HIPAA regulations. One of the pieces of information that needs to be logged is the username of the person who ran the report. Since these reports will be run from our Crystal Enterprise server I can get this from the CurrentCEUserName variable but I am looking for a way to pass this value to a stored procedure that will not only return the records for the report, but also log the disclosure in our PHI disclosure tracking table. I know you can pass a parameter to a stored procedure but I dont know how, or if it is even possible, to pass a run time variable. This is an urgent problem that I need to find a solution for. Any help would be appreciated.
    Thank you.

    Here it is. Right now, when i press te "Go" it runs for the specific time i've set and when its done the variable "Run" is set true. When i call this VI from another VI it waits for the loop to be finished before it will read the variable.
    Regards
    Viktor
    Attachments:
    Untitled 2.vi ‏26 KB

Maybe you are looking for