Run an Insert in the temporary table in SQL Server

Asked

Viewed 225 times

1

I have the following code below.

declare @ac varchar(max) = '(' + replace('2398,2399,2405,2407,2523,3509,3510,3518,3523,3524,3601,3859,4713,4728,4735,47362398,2399,2405,2407,2523,3509,3510,3518,3523,3524,3601,3859,4713,4728,4735,4736',',','),(') + ')'

select @ac

declare

@Mylist table (number bigint)

Insert into @Mylist values @ac

select * from @Mylist

but for some reason this not going already tried a cast what could be ?

1 answer

1


Try it like this:

declare @ac varchar(max)
declare @myList table (ac varchar(max))
begin
    set @ac = '(' + replace('2398,2399,2405,2407,2523,3509,3510,3518,3523,3524,3601,'+
                         '3859,4713,4728,4735,47362398,2399,2405,2407,2523,3509,' +                        '3510,3518,3523,3524,3601,3859,4713,4728,4735,4736',',','),(') + ')'
    insert into @myList values ( @ac )
    select * from @myList
end

Browser other questions tagged

You are not signed in. Login or sign up in order to post.