Steam
Steam

Reputation: 9856

Copy data from one column into another column

I want to move data from Column Col11 of DB1.Table1 into Col555 of DB2.Table7, based on a certain condition. How do I do it ? Is there a statement like -

select Col11 from DB1.Table1
into Col555 of Db2.Table7
where Col11 = 'Important'

Upvotes: 2

Views: 8091

Answers (3)

Yosi Dahari
Yosi Dahari

Reputation: 6999

You don't need COPY or INSERT but UPDATE(using JOIN):

UPDATE [DB2].[Table7]
SET [Table7].[Col555] = [Table1].[Col11]
FROM [Table1] JOIN [Table7] ON -- add the base for the join here...
WHERE [Table1].[Coll] = 'Important'

See this post for more details: SQL update query using joins

Upvotes: 2

DeanG
DeanG

Reputation: 647

INSERT INTO [DB2].[Table7] (Col555)
SELECT [Table1].[Col11]
FROM [DB1].[Table1]
WHERE [Table1].[Coll] = 'Important'

--May need .[dbo] or schema name between database and table names.

Upvotes: 0

jcwrequests
jcwrequests

Reputation: 1130

  INSERT INTO DB2.TABLE2(col555)
  SELECT Col11 FrOM DB1.TABLE1
  WHERE  Col11 = 'important'

Upvotes: 0

Related Questions