Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub Query in Select List truncation error

Status
Not open for further replies.

bajo71

Programmer
Joined
Aug 6, 2007
Messages
135
Location
US
Hello,

I have an extremely long SQL statement that I'm trying to write in the Select List. Basically,it's the following repeated three times(with different tables each time). Problem is, I cannot get around having to write the entire Select statement per the conditional argument. If there was a way, this query would be much smaller.

Any ideas would be greatly appreciated.

IIf(Exists (SELECT TOP 1 [COST_PER_TREATMENT] FROM refZeroBalClinicLookup rzc WHERE [tblDSI].[FAC_CODE]=rzc.[CLINIC_ZERO_INS_CODE] AND [tblDSI].[PRIM_INS]=rzc.[CLINIC_ZERO_INS_NAME]),(SELECT TOP 1 [COST_PER_TREATMENT] FROM refZeroBalClinicLookup rzc WHERE [tblDSI].[FAC_CODE]=rzc.[CLINIC_ZERO_INS_CODE] AND [tblDSI].[PRIM_INS]=rzc.[CLINIC_ZERO_INS_NAME]),...
 
use left joins
Code:
Select * ,nz(rsz.COST_PER_TREATMENT,Sot.COST_PER_TREATMENT)
from tblDSI nz(COST_PER_TREATMENT,)
left join refZeroBalClinicLookup Rzc
on [tblDSI].[PRIM_INS]=rzc.[CLINIC_ZERO_INS_NAME]
left join SomeOtherTable SOT
on [tblDSI].[PRIM_INS]=Sot.[CLINIC_ZERO_INS_NAME]

what dose this give you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top