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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 need help to query

Author  Topic 

ibin
Starting Member

26 Posts

Posted - 2009-10-08 : 01:34:47
Hi i want to update the #main table 's actdate and date column with values from #temp.the tables are as below. How can i do this.??


CREATE TABLE #Temp (
LinkID varchar(6),
Desc1-actdate datetime,
Desc1-date datetime,
Desc2-actdate datetime,
Desc2-date datetime)
)
INSERT INTO #Temp (LinkID , Desc1-actdate, Desc1-date,Desc2-actdate, Desc2-date) VALUES ('ABC','1/1/2009','1/2/2009','1/3/2009','1/4/2009')
INSERT INTO #Temp (LinkID , Desc1-actdate, Desc1-date,Desc2-actdate, Desc2-date) VALUES ('def','3/1/2009','5/2/2009','1/3/2009','1/4/2009')
INSERT INTO #Temp (LinkID , Desc1-actdate, Desc1-date,Desc2-actdate, Desc2-date)VALUES ('ghi','4/1/2009','6/2/2009','1/3/2009','1/4/2009')

CREATE TABLE #Lookup(
ID varchar(6),
Desc nvarchar(max))
INSERT INTO #Lookup(ID , Desc) VALUES ('a1','Desc1')
INSERT INTO #Lookup(ID , Desc) VALUES ('a2','Desc2')
INSERT INTO #Lookup(ID , Desc) VALUES ('a3','Desc3')

CREATE TABLE #Main (
LinkID varchar(6),
LookupID varchar(6),
actdate datetime,
date datetime
)
INSERT INTO #Main (LinkID , LookupID , actdate ,date) VALUES ('ABC','a1','1/2/2009','1/3/2009')
INSERT INTO #Main (LinkID , LookupID , actdate ,date) VALUES ('ABC','a2','1/2/2009','1/3/2009')
INSERT INTO #Main (LinkID , LookupID , actdate ,date) VALUES ('def','a1','3/1/2009','5/2/2009')
INSERT INTO #Main (LinkID , LookupID , actdate ,date) VALUES ('ghi','a3','4/1/2009','6/2/2009')

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-08 : 01:42:06
Here it is

update m set m.actdate=t.Desc1_actdate,m.date=t.Desc1_date from
#main m inner join #Temp t on m.linkid=t.linkid

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

ibin
Starting Member

26 Posts

Posted - 2009-10-12 : 02:43:47
Thanks for ur reply.. but guess u missed the lookup id in main table..
for a single LinkID there can be multiple Lookup id's and in the temp table i have only the description.
Go to Top of Page
   

- Advertisement -