Table-Valued Parameter in Stored Procedure and the Entity Framework 4.0

后端 未结 4 618
挽巷
挽巷 2020-12-10 15:40

I have a stored procedure in SQL Server 2008 called \'GetPrices\' with a Table-Valued Parameter called \'StoreIDs\'.

This is the type i created for this TVP:

4条回答
  •  青春惊慌失措
    2020-12-10 16:31

    I agree that passing in a CSV sting is the best solution in this case. I would like to propose simpler way to split csv string, without creating tables and functions, by using CTE:

    declare @separator char(1);
    set @separator = ',';
    
    ;with baseCte as
    (select left(@ValueList, charindex(@separator, @ValueList) - 1) as Value,
    substring(@ValueList, charindex(@separator, @ValueList) + 1, len(@ValueList)) 
    as rest
    union all
    select left(rest, charindex(@separator, rest) - 1) as Value, 
    substring(rest, charindex(@separator, rest) + 1, len(rest)) from baseCte
    where len(rest) > 1
    )
    select Value from baseCte
    OPTION (MAXRECURSION 0);
    

提交回复
热议问题