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 |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-06-14 : 07:06:22
|
Hi,As you can see the following two tables have different data.So the IDs will vary.Can you let me know the sql query to update table1Thanks-----------------Table1IndexID Name ParentIndexID1 BR DATED NULL2 BR IPE NULL3 BR NYMEX NULL4 DUBAI NULL5 F10MEDCC NULL6 F10MEDFC NULL7 F10NWECC NULL8 F10NWEFB NULL9 F10NWEFC NULL10 xx NULL...13 BR(1,1) NULL...20 WTI NYMEX Null...156 z Null--------------------Table2table2ID table2Name Table2ParentIndexID1 BR DATED 1292 BR IPE 563 BR NYMEX 24 DUBAI 1295 F10MEDCC 96 F10MEDFC 97 F10NWECC 98 F10NWEFB 99 F10NWEFC 13...13 F35NWEFB 129...56 WTI NYMEX NULL...129 BR(1,1) 131...131 xx NULL------------------The idea is to come up with an update query to update table1to have this kind of data. ThanksIndexID Name ParentIndexID1 BR DATED 132 BR IPE 203 BR NYMEX 24 DUBAI 135 F10MEDCC 126 F10MEDFC 127 F10NWECC 128 F10NWEFB 1212 F10NWEFC NULL.........This is what i have so far:update Table1.ParentIndexIDset Table1.ParentIndexID = from Table1 inner join Table2 on Table1.IndexID = Table2.table2ParentIndexID |
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2007-06-14 : 08:18:27
|
[code]UPDATE T1SET ParentIndexID = T2.table2ParentIDFROM Table1 T1 JOIN Table2 T2 ON T1.[Name] = T2.table2Name AND table2ParentID IS NOT NULL[/code]or[code]UPDATE T1SET ParentIndexID = T4.IndexIDFROM Table1 T1 JOIN Table2 T2 ON T1.[Name] = T2.table2Name AND table2ParentID IS NOT NULL JOIN Table2 T3 ON T2.table2ParentID = T3.table2ID JOIN Table1 T4 ON T3.table2Name = T4.[Name][/code] |
 |
|
skn
Starting Member
1 Post |
Posted - 2011-06-02 : 04:59:25
|
hai,i have 3 tables names dbo.tblissue,dbo.tblissueDetails,dbo.tblcounterdetailsi want to retrieve counterid and stockid from the table dbo.tblcounterdetails,then unit and Gwgt from table dbo.issuedetails,with the condition tasktype=1,which is situated in the table dbo.tblissuewhen i executed the query it will not take the value of task type....... i think you get the relation between these tables can be identified from the code block..... SELECT CD.CounterId AS COUNTER, CD.StockId AS Stock, ISNULL(SUM(TD.Unit),0) AS Unit, ISNULL(SUM(TD.GWgt),0) AS Wgt, I.TaskType FROM tblCounterDetails CD LEFT OUTER JOIN tblIssueDetails TD ON TD.CNo = CD.CounterId AND TD.ItemId = CD.ItemId LEFT OUTER JOIN tblIssue I ON I.Id = TD.IId AND I.TaskType = 0 GROUP BY CD.CounterId, CD.StockId, I.TaskTypein this code the line LEFT OUTER JOIN tblIssue I ON I.Id = TD.IId AND I.TaskType = 0 is not working...it may be the join problem with the third table.....will you please help me to make the code completely working? thank you in advance.. |
 |
|
|
|
|
|
|