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 |
|
insanepaul
Posting Yak Master
178 Posts |
Posted - 2009-02-03 : 06:17:42
|
I have a select command that should return 2 columns as below but the second column (lfieldtype) references another table 'lufieldtype' which I'm stuck on an error message. Rather than getting the ID I want to get the corresponding sDescription from that table. I can't figure out what i'm doing wrong. If I just select the first column I get the correct results.Example of the 2 tables:Table lufieldtype ID sDescription1 Readonly2 Writeonly3 TextTable strtoolinfostext lfieldtypesometext... 1sometext... 2sometext... 1etc..select stext, (SELECT lfieldtype FROM lufieldtype WHERE (lfieldtypeid = strTool.lfieldtype)) as hhh, loptionidFROM strtoolinfoWHERE ltoolinfoid not in (select ltoolinfoid from strlnktooltoolinfo WHERE stoolguid = '{79be4f69-6081-4029-8fe7-802048030b5b}') |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-02-03 : 06:20:19
|
quote: Originally posted by insanepaul I have a select command that should return 2 columns as below but the second column (lfieldtype) references another table 'lufieldtype' which I'm stuck on an error message. Rather than getting the ID I want to get the corresponding sDescription from that table. I can't figure out what i'm doing wrong. If I just select the first column I get the correct results.Example of the 2 tables:Table lufieldtype ID sDescription1 Readonly2 Writeonly3 TextTable strtoolinfostext lfieldtypesometext... 1sometext... 2sometext... 1etc..select stext, (SELECT lfieldtype FROM lufieldtype WHERE (lfieldtypeid = strtoolinfo.lfieldtypeid)) as hhh, loptionidFROM strtoolinfoWHERE ltoolinfoid not in (select ltoolinfoid from strlnktooltoolinfo WHERE stoolguid = '{79be4f69-6081-4029-8fe7-802048030b5b}')
Jai Krishna |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-03 : 06:21:24
|
| try like this rather than subqueryselect s.stext, l.lfieldtype as hhh, s.loptionidFROM strtoolinfo as sinner join lufieldtype l on l.lfieldtypeid = s.lfieldtypeWHERE s.ltoolinfoid not in (select ltoolinfoid from strlnktooltoolinfo WHERE stoolguid = '{79be4f69-6081-4029-8fe7-802048030b5b}') |
 |
|
|
insanepaul
Posting Yak Master
178 Posts |
Posted - 2009-02-03 : 06:23:34
|
| wow that was quick and correct...Thanks - was driving me insane |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-03 : 06:24:25
|
quote: Originally posted by insanepaul wow that was quick and correct...Thanks - was driving me insane
welcome |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-03 : 09:02:36
|
try this too and see if performance is any betterselect s.stext, l.lfieldtype as hhh, s.loptionidFROM strtoolinfo as sinner join lufieldtype l on l.lfieldtypeid = s.lfieldtypeWHERE NOT EXISTS (select 1 from strlnktooltoolinfo WHERE ltoolinfoid=s.ltoolinfoid AND stoolguid = '{79be4f69-6081-4029-8fe7-802048030b5b}') |
 |
|
|
|
|
|