Insert multiple rows into temp table with one command in SQL2005

前端 未结 3 2083
耶瑟儿~
耶瑟儿~ 2021-01-15 09:23

I\'ve got some data in the following format:

-1,-1,-1,-1,701,-1,-1,-1,-1,-1,304,390,403,435,438,439,442,455

I need to insert it into a temp

3条回答
  •  臣服心动
    2021-01-15 09:56

    You can create a query dynamically like this:

    declare @sql varchar(1000)
    set @sql = 'insert into #TEMP select ' + replace(@values, ',', ' union all select ')
    exec @sql
    

    As always when creating queries dynamically, you have to be careful so that you only use trusted data.

提交回复
热议问题