How to pass an array into a SQL Server stored procedure

前端 未结 11 2421
轻奢々
轻奢々 2020-11-21 23:28

How to pass an array into a SQL Server stored procedure?

For example, I have a list of employees. I want to use this list as a table and join it with another table.

11条回答
  •  梦如初夏
    2020-11-21 23:40

    CREATE TYPE dumyTable
    AS TABLE
    (
      RateCodeId int,
      RateLowerRange int,
      RateHigherRange int,
      RateRangeValue int
    );
    GO
    CREATE PROCEDURE spInsertRateRanges
      @dt AS dumyTable READONLY
    AS
    BEGIN
      SET NOCOUNT ON;
    
      INSERT  tblRateCodeRange(RateCodeId,RateLowerRange,RateHigherRange,RateRangeValue) 
      SELECT * 
      FROM @dt 
    END
    

提交回复
热议问题