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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Liam neesan
  • 2,282
  • 6
  • 33
  • 72
  • 1
    Possible duplicate of [Parameterize an SQL IN clause](https://stackoverflow.com/questions/337704/parameterize-an-sql-in-clause) – GSerg Feb 19 '18 at 19:41
  • @Gserg can you check my update. And please remove duplicate. I am trying this since two days – Liam neesan Feb 19 '18 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. – GSerg Feb 19 '18 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? – Liam neesan Feb 19 '18 at 20:29

0 Answers0