Carlos Mendieta Carlos Mendieta - 1 month ago 7
SQL Question

In SQL, how can I insert a static column value while doing a INSERT INTO SELECT?

I need to write an SQL statement that will copy rows and insert them into the same table; however, on one of the fields, I want to write a static value for each row copied. I'm not sure how to do this, but here's what I have so far:

INSERT INTO [xxx].[dbo].[TABLEX]
SELECT [NAME]
,[DESC]
,[MODULE]
,[OWNER] <=== I want all newly inserted rows to have "TERRY" as the owner
FROM [xxx].[dbo].[TABLEX]
WHERE OWNER = 'SAM' AND MODULE = 'ACC'


Thanks so much for the help

Answer
INSERT INTO [xxx].[dbo].[TABLEX]
SELECT  [NAME]
  ,[DESC]
  ,[MODULE]
  ,'Terry'  <=== I want all newly inserted rows to have "TERRY" as the owner
FROM [xxx].[dbo].[TABLEX]
WHERE OWNER = 'SAM' AND MODULE = 'ACC'