| Author |
Topic |
|
hisouka
Starting Member
28 Posts |
Posted - 2009-02-08 : 23:27:43
|
| Hi guys, I have Query:Select ID, Name, (SELECT Extract FROM tblExtract WHERE ExtractID = ID) AS ExtractNote FROM tblEmployeesI want to refer the ID colored in RED to ID Colored in Greenbut it produce error that Invalid name for ID colored in REdIs there anything i forgot? thanks |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-02-08 : 23:28:57
|
| Select ID, Name, (SELECT Extract FROM tblExtract WHERE ExtractID = t.ID) AS ExtractNote FROM tblEmployees tJai Krishna |
 |
|
|
hisouka
Starting Member
28 Posts |
Posted - 2009-02-08 : 23:43:35
|
| How About this:SELECT Name, (SELECT TOP 1 ID FROM tblMain) AS EstimateID, (SELECT Value FROM EstimateValue WHERE ID = EstimateID) as VAlue FROM tblValuationI want to refer the EstimateID colored in RED to EstimateID Colored in Greenbut it produce error that Invalid name for ID colored in REd |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-08 : 23:49:08
|
quote: Originally posted by Jai Krishna Select ID, Name, (SELECT Extract FROM tblExtract WHERE ExtractID = t.ID) AS ExtractNote FROM tblEmployees tJai Krishna
What if ID has multiple extracts? It won't work in that scenerio.Select Z.ID,Z.Name,Y.Extractfrom tblEmployees Z inner join tblExtract YOn Z.ID = Y.ID |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-08 : 23:50:55
|
quote: Originally posted by hisouka How About this:SELECT Name, (SELECT TOP 1 ID FROM tblMain) AS EstimateID, (SELECT Value FROM EstimateValue WHERE ID = EstimateID) as VAlue FROM tblValuationI want to refer the EstimateID colored in RED to EstimateID Colored in Greenbut it produce error that Invalid name for ID colored in REd
Please Explain clearly what you are looking for. Maybe with Sample data and Expected output. |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-02-08 : 23:51:19
|
quote: Originally posted by sodeep
quote: Originally posted by Jai Krishna Select ID, Name, (SELECT Extract FROM tblExtract WHERE ExtractID = t.ID) AS ExtractNote FROM tblEmployees tJai Krishna
What if ID has multiple extracts? It won't work in that scenerio.Select Z.ID,Z.Name,Y.Extractfrom tblEmployees Z inner join tblExtract YOn Z.ID = Y.ID
I have answered assuming that ExtractID ,ID are Identity ColumnsJai Krishna |
 |
|
|
hisouka
Starting Member
28 Posts |
Posted - 2009-02-09 : 00:28:59
|
| SELECT Name, (SELECT TOP 1 ID FROM tblMain) AS EstimateID, (SELECT Value FROM EstimateValue WHERE ID = EstimateID) as VAlue FROM tblValuationInstead of:SELECT Name, (SELECT TOP 1 ID FROM tblMain) AS EstimateID, (SELECT Value FROM EstimateValue WHERE ID = (SELECT TOP 1 ID FROM tblMain)) as VAlue FROM tblValuationrepeating (SELECT TOP 1 ID FROM tblMain)But it produces error |
 |
|
|
hisouka
Starting Member
28 Posts |
Posted - 2009-02-09 : 00:52:12
|
| In Short I want to User Alias from a Sub Query |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-02-09 : 00:57:47
|
| Try thisSELECT v.Name,m.estimateid,e.valueFROM tblValuation vINNER JOIN tblMain m ON (v.commoncolid = m.commoncolid)INNER JOIN EstimateValue e ON (e.id = m.id)WHERE m.id = 1Jai Krishna |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-09 : 03:36:37
|
quote: Originally posted by hisouka SELECT Name, (SELECT TOP 1 ID FROM tblMain) AS EstimateID, (SELECT Value FROM EstimateValue WHERE ID = EstimateID) as VAlue FROM tblValuationInstead of:SELECT Name, (SELECT TOP 1 ID FROM tblMain) AS EstimateID, (SELECT Value FROM EstimateValue WHERE ID = (SELECT TOP 1 ID FROM tblMain)) as VAlue FROM tblValuationrepeating (SELECT TOP 1 ID FROM tblMain)But it produces error
you've not linked tblMain to tblValuation. how are they related? as of now it just takes a random row from tblMain |
 |
|
|
|