I have searched online and tried the below solution but it does not work; it doesn’t enter a row into the table..
INSERT INTO [CollisionBegin]
SELECT '999-999-99999-9999-9999', [LocalNum], [version], [Submitted]
FROM [CollisionBegin]
WHERE [UniqueColID] = '2C024576-10BB-4A12-8B6E-BB03191866DE';
What I am trying to do: find a row in the table with UniqueColdID="2C024576-10BB-4A12-8B6E-BB03191866DE"
This should retrieve ALL of the columns that correspond to a row with this UniqueColID. Now I want to reinsert this record BUT with a NEW UniqueColID, "999-999-99999-9999-9999".
The above code was a solution I found around the web but it did not work for me because after I execute that statement in my stored procedure, nothing happened.
This is my stored procedure:
ALTER PROCEDURE [dbo].[AmendInsertDuplicateFields]
AS
BEGIN
INSERT INTO [MVCNew].[dbo].[CollisionBegin]
SELECT
'999-999-99999-9999-9999', [LocalNum], [version], [Submitted]
FROM
[MVCNew].[dbo].[CollisionBegin]
WHERE
[UniqueColID] = '2C024576-10BB-4A12-8B6E-BB03191866DE';
END
I know that I have to provide the values explicitly to the insert:
INSERT INTO [MVCNew].[dbo].[CollisionBegin] (Column1, Column2, Column3, etc)
SELECT Column1, Column2, Column3, etc
FROM...
BUT I have about 8 tables I need to do this for and 30 columns per table so that would be confusing..
I just tried:
CREATE TEMPORARY TABLE chan2 ENGINE=MEMORY SELECT * FROM [MVCNew].[dbo].[PrideMVCCollisionBegin] WHERE UniqueColID='2C024576-10BB-4A12-8B6E-BB03191866DE';
UPDATE chan2 SET UniqueColID='999-999-99999-9999-9999';
INSERT INTO [MVCNew].[dbo].[PrideMVCCollisionBegin] SELECT * FROM chan2;
DROP TABLE chan2;
But I get the error:
Unknown object type 'TEMPORARY' used in a CREATE, DROP, or ALTER statement.
See my answer on your your other thread on this same topic. In short, yes, I would suggest manually listing all the fields, but no, you don’t need to type them all yourself.
If you are really motivated to do this without listing all the fields, you’d need to get into some dynamic SQL (or, say, a SQLCLR procedure) to make it happen. It can be done, and it should work, but it’s much more complicated for something that really is probably best solved by writing the queries the conventional way.