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 |
|
mrgalvan
Starting Member
9 Posts |
Posted - 2006-07-20 : 16:17:53
|
| I have this subquery that I'm trying to get info from the two seperate tables to show up, but I only get one or the other.-- This report is for the DC. This report is to look at what items -- come in a kit and what the inventory levels looks like at the -- time the report is run. 07/18/06 mjgSELECT I.ItemID, D.ShortDesc, KI.ItemID, KD.ShortDescFROM timKitCompList KL INNER JOIN timItem I ON KL.CompItemKey = I.ItemKey INNER JOIN timitemdescription D ON I.ItemKey = D.ItemKeyWHERE EXISTS (SELECT KI.ItemID AS KitItemNo, KD.ShortDesc AS KitItemDescFROM timKit K INNER JOIN timItem KI ON K.KitItemKey = KI.ItemKey INNER JOIN timitemdescription KD ON KI.ItemKey = KD.ItemKey)Here are the error messages that I get:Server: Msg 107, Level 16, State 2, Line 4The column prefix 'KI' does not match with a table name or alias name used in the query.Server: Msg 107, Level 16, State 1, Line 4The column prefix 'KD' does not match with a table name or alias name used in the query. |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-07-20 : 16:38:56
|
| U have 4 tables, but u mention 2 tables ?Why do u use "Exists"U cannot use Aliases of the Query for Exist check, in the main QueryWithout knowing ur Joining / Conditions ... hard to give a solution. but seems to be not complex.Srinika |
 |
|
|
tonymorell10
Yak Posting Veteran
90 Posts |
Posted - 2006-07-20 : 16:39:02
|
| Instead of a subquery, would not another inner join get you what you need?SELECT DISTINCT K.ItemID, D.ShortDescFROM timKitCompList KLINNER JOIN timItem I ON KL.CompItemKey = I.ItemKeyINNER JOIN timitemdescription D ON I.ItemKey = D.ItemKeyINNER JOIN timKit K ON K.KitItemKey = I.ItemKey AND K.KitItemKey = D.ItemKey |
 |
|
|
mrgalvan
Starting Member
9 Posts |
Posted - 2006-07-20 : 16:51:27
|
quote: Originally posted by Srinika U have 4 tables, but u mention 2 tables ?Why do u use "Exists"U cannot use Aliases of the Query for Exist check, in the main QueryWithout knowing ur Joining / Conditions ... hard to give a solution. but seems to be not complex.Srinika
I guess I'm trying to get the timKit and the timKitCompList to both give me their ItemIDs as well as their descriptions. I can run the two seperate queries alone and get what I'm looking for, but when I try to do them together it doesn't like it. What am I doing wrong. By the way, I'm very new to SQL.Thanks,USE Mas500_AppSELECT timItem.ItemID, timItemDescription.ShortDesc, timKit.KitItemKeyFROM timKitCompList INNER JOIN timItem ON timKitComplist.CompItemKey = timItem.ItemKeyINNER JOIN timitemdescription ON timItem.ItemKey = timItemDescription.ItemKeyINNER JOIN timKit ON timKitCompList.KitItemKey = timKit.KitItemKeyWHERE EXISTS (SELECT timItem.ItemID, timItemDescription.ShortDescFROM timKit INNER JOIN timItem ON timKit.KitItemKey = timItem.ItemKeyINNER JOIN timitemdescription ON timItem.ItemKey = timItemDescription.ItemKey)GROUP BY timItem.ItemID, timItemDescription.ShortDesc, timkit.KitItemKey |
 |
|
|
tonymorell10
Yak Posting Veteran
90 Posts |
Posted - 2006-07-20 : 17:08:07
|
| SELECT DISTINCT I.ItemID, D.ShortDesc, K.ItemIDFROM timKitCompList KLINNER JOIN timItem I ON KL.CompItemKey = I.ItemKeyINNER JOIN timitemdescription D ON I.ItemKey = D.ItemKeyINNER JOIN timKit K ON K.KitItemKey = I.ItemKeyAND K.KitItemKey = D.ItemKey |
 |
|
|
|
|
|
|
|