Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update result set 1

Status
Not open for further replies.

kingstonr

Programmer
Dec 5, 2005
26
US
HI,

I have two resultset one result set is below

id pdate
1 2006-12-30

another temptable resultset

id pdate
1 null

I want to update the temptable pdate from the previous resultsset where the result is holded in CTE.
i.e update the temptable pdate with value 2006-12-30.

can somebody help me out in this.


Thanks
 
What is TempTable? Temporary table or table variable? How these resultsets are created?

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
They are in temporay Table.
Both resultset are created separately.

Now I have Two resultset.one in commontable expression.
other in #temp table.

Now I want to merge two results.

CTE resultset has

id pdate
1 2/30/2006

#temp table has

id pdate
1 null.

Now I want update #temp table null value with value from CTE.

 
Code:
UPDATE #TempTable
       SET PDate = CTE.PDate
FROM #TempTable
INNER JOIN CTE ON #TempTable.Id = CTE.Id
WHERE #TempTable.PDate IS NULL
not tested at all

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Why do you want to do that?

1. It's a temporary table, not a permanent one.
2. Since you have the values in the other permanent table why don't you just drop the temporary table and use the permanent table OR if you really have to, copy the permanent table to a new temporary table.

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top