Oleg
Oleg

Reputation: 179

SQL Server : duplicate rows while changing a columns value

I have a table T, say

1 | a
2 | a

I want to duplicate its rows while changing the value of the second column to b, so as to have

1 | a
2 | a
1 | b
2 | b

I came to

INSERT INTO T(col1, col2) 
   SELECT col1, 'b' 
   FROM T

but I get an error

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Upvotes: 0

Views: 1303

Answers (1)

MaxiWheat
MaxiWheat

Reputation: 6251

Remove those extra parentheses in the SELECT :

INSERT INTO T(col1, col2) 
SELECT col1, 'b' AS col2 FROM T;

Upvotes: 1

Related Questions