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 |
|
PeterG
Posting Yak Master
156 Posts |
Posted - 2003-07-03 : 16:36:48
|
| My table structure/data:AAAlngIndex acct cycle amount tax1 123 3/1/2003 12.34 1.122 123 3/1/2003 111.23 10.253 123 4/1/2003 86.88 7.784 222 3/1/2003 3.45 .285 222 5/2/2003 12.23 1.066 333 3/1/2003 123.23 11.12BBBlngIndex description quantity unit unitcost1 pens 1 box 10.251 pencils 2 boxes 3.355 crayon 1 box 1.126 paint 2 gals 25.25My recordset should be:1 123 3/1/2003 12.34 1.12 pens 1 box 10.251 123 3/1/2003 12.34 1.12 pencils 2 boxes 3.352 123 3/1/2003 111.23 10.253 123 4/1/2003 86.88 7.78What I want to do is to be able to select all records from table AAA with acct=123, and link AAA.lngIndex = BBB.lngIndex. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-07-03 : 16:39:57
|
| You almost have the query in the question.select *from AAA , BBBwhere AAA.lngIndex = BBB.lngIndexand AAA.acct=123select *from AAA join BBBon AAA.lngIndex = BBB.lngIndexwhere AAA.acct=123==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-07-03 : 16:40:30
|
| select AAA.lngINdex, acct, cycle, amount, tax, description, unit, unitcostfromAAAleft outer joinBBBonAAA.lngINdex = BBB.lngIndexwhereacct = 123- Jeff |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-07-03 : 16:41:28
|
| nigel -- based on his sample data and expected results, i think he needs an outer join...- Jeff |
 |
|
|
PeterG
Posting Yak Master
156 Posts |
Posted - 2003-07-03 : 16:59:30
|
| Thanks for the quck reply Nigel and Jeff.Here's how I reworded the query to apply to my tables:SELECT T.txtAccountNum, T.dteCycleDate, T.dteTransacDate, T.txtMerchantName, T.curTransacAmnt, T.txtTransacCode,P.ProductCode, P.description, P.Quantity, P.Unit, P.UnitCostFROM Transactions T left outer join PurchaseDetails P on T.lngIndex=P.lngIndex WHERE (T.txtAccountNum = '0000000000040888') This is giving me NULL values for the PurchaseDetails fields. Why? If I do an inner join, I don't get a record at all. |
 |
|
|
PeterG
Posting Yak Master
156 Posts |
Posted - 2003-07-03 : 17:03:25
|
| Never mind. I had the wrong parameters. Thanks anyways. |
 |
|
|
|
|
|
|
|