tags:

views:

34

answers:

2

Hi all... I want to copy data from one column to another column of other table..so how i should i do that.. i did following thing

Update tblindiantime Set CountryName =(Select contacts.BusinessCountry From contacts) 

but its not working..

i want to copy "BusinessCountry" column of contact table to "CountryName" column of tblindiantime...

+1  A: 

In SQL Server 2008 you can use a multi-table update as follows:

UPDATE tblindiantime 
SET tblindiantime.CountryName = contacts.BusinessCountry
FROM tblindiantime 
JOIN contacts
ON -- join condition here

You need a join condition to specify which row should be updated.

If the target table is currently empty then you should use an INSERT instead:

INSERT INTO tblindiantime (CountryName)
SELECT BusinessCountry FROM contacts
Mark Byers
Hi thankx for ur rep but it is showing me following errorCannot insert the value NULL into column 'IndianTime', table 'tqms.dbo.tblindiantime'; column does not allow nulls. INSERT fails.The statement has been terminated.
A: 

Hope you have key field is two tables.

 Update tblindiantime t
   Set CountryName = (Select contacts.BusinessCountry 
                     From contacts c WHERE c.Key = t.Key 
                     )
Michael Pakhantsov