I can copy a row and change the value of a single field in the same table like this which works perfectly fine:
INSERT INTO myTable (foo,bar)
SELECT foo,'new bar'
FROM myTable
WHERE rowIndex=5
But I'd like to replace 'new bar' with an inline variable. I have tried this to no avail:
DECLARE @Bar varchar(50) = 'new bar'
INSERT INTO myTable (foo,bar)
SELECT foo,@Bar
FROM myTable
WHERE rowIndex=5
I just get thrown an error that says @Bar is an invalid column.
Is there a way to do this?
DECLAREand theINSERTin the same batch?