0

I have to pass the multivalue parameter to a stored procedure. The datatype which is passing from C# code is string[].

This is my stored procedure

CREATE PROCEDURE spRecords
    @Department VARCHAR(MAX) = NULL
AS
BEGIN
    SELECT
        ItemDetails,
        Total,
        Department
    FROM
        ItemRecords
    WHERE
        (Department.Name IN (@Department) OR @Department IS NULL)
END

I get the following error message

Cannot convert from string[] to string

I saw this stack overflow second answer to declare variable like @INFO_ARRAY ARRAY nvarchar(max). But I don't know how I should apply that in my case

Update

I don't want to change any code from C#. I am using one tool that will directly pass string[] array parameter like datasource

4
  • 1
    Possible duplicate of Parameterize an SQL IN clause Commented Feb 19, 2018 at 19:41
  • @Gserg can you check my update. And please remove duplicate. I am trying this since two days Commented Feb 19, 2018 at 19:54
  • It's not about what you want to do, it's about what is possible to do, and that is what the duplicate question shows. You don't sent string[] to an SQL Server database because there is no corresponding server data type. Commented Feb 19, 2018 at 20:13
  • @GSerg Can we pass parameter as string like Fruits,Vegetables,IceCream and then convert into 'Fruits','Vegetables','IceCream' set it to @department? Commented Feb 19, 2018 at 20:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.