Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jfm
Posting Yak Master
145 Posts |
Posted - 2013-04-22 : 10:44:23
|
Hi there, I have table1 with col_date and col_id I need to copy col_date from table1 into table_2, when Col_id = Col_id from table2Any idea?thank you |
|
jfm
Posting Yak Master
145 Posts |
Posted - 2013-04-22 : 10:48:26
|
Hi there, I have table1 with col_date and col_id I need to copy col_date from table1 into table_2, when Col_id from table1 = Col_id from table2Any idea?thank you |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2013-04-22 : 11:14:24
|
Use the UPDATE and JOIN , here is an example , using the details you posted :create table #temp1(col_id INT , col_date datetime)create table #temp2(col_id INT , col_date datetime)INSERT INTO #temp1 select 1, '01-01-2001'UNIONselect 2,'02-02-2001'INSERT INTO #temp2 select 1, '03-03-2001'UNIONselect 2,'04-04-2001'UPDATE #temp2 SET col_date = B.col_dateFROM #temp2 AS A INNER JOIN #temp1 AS BON A.col_id = B.col_iddrop table #temp1drop table #temp2Read more on UPDATE and JOIN on http://www.sqlserver-dba.com/2011/06/t-sql-update-join-on-a-table.htmlJack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
jfm
Posting Yak Master
145 Posts |
Posted - 2013-04-22 : 11:31:56
|
Select Col_Id, col_date from Table1inner join table on table1.col_id = table2.col_idIm missing something here to make it workAny tip?Thanks |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2013-04-22 : 15:09:43
|
That will return the combined recordset from Table 1 and Table 2 - of rows joined at col_id. Your initial request is to UPDATE ?Jack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
jfm
Posting Yak Master
145 Posts |
Posted - 2013-04-23 : 04:18:30
|
I want to gather the info that connects via id_Col. But is not working properly... No Jackv, Im looking to extract the data, not update. but still not working the query..Thank you |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2013-04-23 : 09:50:23
|
You say it's not working properly - as suggested by bandi - could you supply , the DDL - an expected resultset and the current resultsetJack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
|
|
|
|
|