Passing array of ints to T-SQL stored proc via entity framework

前端 未结 3 358
悲&欢浪女
悲&欢浪女 2020-12-18 07:45

I\'ve read many posts and think I understand the concepts, but my small array of ints fails to pass from a C#/EF module to a SQL Server stored proc. Hoping other eyes can s

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 08:36

    I know this has been answered by found a different way that might help someone else out there

    STRING_SPLIT

    declare @intArray nvarchar(1000)
    set @intArray = '1,2,3,4,5'
    select value from STRING_SPLIT(@intArray , ',')
    

    This will return a new table with the numbers in your @intArray

    Then you just need to use it as a normal table

    select * from myMainTable where Id in (select value from STRING_SPLIT(@intArray , ','))
    

提交回复
热议问题