Search code examples
sqlsql-server-2008insertsql-server-2008-r2multiple-records

Insert Multipule rows single insert query


First query I'm getting user_id records like below :

1
14
22
38
39
54
68
74

Now i want to insert above user_id's in another table in single query, like below :

INSERT INTO tbl_Channel_Subscriber(user_id,channel_id,status,EntDate) VALUES(@user_id,@channel_id,@status,@EntDate).

How can i insert new record with single insert query


Solution

  • Don't use 2 queries. Do it in one and add the variables to the first query

    INSERT INTO tbl_Channel_Subscriber(user_id,channel_id,status,EntDate) 
    select user_id, @channel_id, @status, @EntDate
    from first_table