SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The multi-part identifier could not be bound


The multi-part identifier could not be bound

Author
Message
kadeshara
kadeshara
SSC-Enthusiastic
SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)

Group: General Forum Members
Points: 171 Visits: 5560
Hi there,

I've read few fixes on this forum and other forums available online, but none were able to help.. so am posting a new question.

I am running the below query but I end up with this error

Msg 4104, Level 16, State 1, Line 144
The multi-part identifier "t1.ClaimID" could not be bound.

Query is

SELECT c.claimnumber AS claimnumber,
tli1.UpdateTime as TranLineItemUT,

FROM cc_claim c

--Transaction Line Item
left outer join (select MAX(tli1.ID) as ID , t1.ClaimID, MAX(tli1.UpdateTime) as UpdateTime
from cc_transactionlineitem tli1
inner join cc_transaction t1 ON t1.id = tli1.transactionid
group by t1.ClaimID) tli1 ON c.ID = t1.ClaimID

Relationship between Transaction (t) and Transaction Line Item (tli1) is One Transaction can be linked to Zero/One/Many Transaction Line Items.

The reason why I need to link to the Transaction table is because the ClaimNumber is stored in that table.

I think this must be to do with One to Many relationship, but I've got no idea how to handle this in my query.

Help.

K
Nabha
Nabha
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1931 Visits: 1815
Not sure if I am overlooking this, the last 'ON' cluase is,

ON c.ID = t1.ClaimID

Dont you think it should be tli1 instead of t1 in t1.ClaimID?

Ohh sorry, you cant use that t1.claimID directrly in ON clause. Give an alias for that and then use it in here!

---------------------------------------------------------------------------------
kadeshara
kadeshara
SSC-Enthusiastic
SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)

Group: General Forum Members
Points: 171 Visits: 5560
Pakki (8/27/2009)
Not sure if I am overlooking this, the last 'ON' cluase is,

ON c.ID = t1.ClaimID

Dont you think it should be tli1 instead of t1 in t1.ClaimID?

Ohh sorry, you cant use that t1.claimID directrly in ON clause. Give an alias for that and then use it in here!


Cant use tli1.ClaimID as ClaimID belongs to Transaction (t1). t1 is the alias for the table :-). I also tried using the full table name but that gave the same error.
Nabha
Nabha
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1931 Visits: 1815
Give some other table name as the alias for the nested table (lets say tli2)

U mean to say this is also giving the same error?

SELECT c.claimnumber AS claimnumber,
tli1.UpdateTime as TranLineItemUT,

FROM cc_claim c

--Transaction Line Item
left outer join (select MAX(tli1.ID) as ID , t1.ClaimID as CLAIM_ID, MAX(tli1.UpdateTime) as UpdateTime
from cc_transactionlineitem tli1
inner join cc_transaction t1 ON t1.id = tli1.transactionid
group by t1.ClaimID) tli2 ON c.ID = tli2.CLAIM_ID



---------------------------------------------------------------------------------
kadeshara
kadeshara
SSC-Enthusiastic
SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)

Group: General Forum Members
Points: 171 Visits: 5560
Pakki (8/27/2009)
Give some other table name as the alias for the nested table (lets say tli2)

U mean to say this is also giving the same error?

SELECT c.claimnumber AS claimnumber,
tli1.UpdateTime as TranLineItemUT,

FROM cc_claim c

--Transaction Line Item
left outer join (select MAX(tli1.ID) as ID , t1.ClaimID as CLAIM_ID, MAX(tli1.UpdateTime) as UpdateTime
from cc_transactionlineitem tli1
inner join cc_transaction t1 ON t1.id = tli1.transactionid
group by t1.ClaimID) tli2 ON c.ID = tli2.CLAIM_ID



Nearly the same error, now it gives me the below error
The multi-part identifier "tli.UpdateTime" could not be bound.

I think this is because tli.UpdateTime is actually coming from nested query in the JOIN?
Nabha
Nabha
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1931 Visits: 1815
Assuming its the tli1.updatetime in the select clause, I am guessing yes. Try giving tli2.updatetime in the select query as well? That is what you need isnt it?

---------------------------------------------------------------------------------
kadeshara
kadeshara
SSC-Enthusiastic
SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)SSC-Enthusiastic (171 reputation)

Group: General Forum Members
Points: 171 Visits: 5560
Fantastic, I got my result.

Looking at the query, I now I understand what mistake I was doing.

Thanks for your help and support.
Nabha
Nabha
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1931 Visits: 1815
You're welcome:-)

---------------------------------------------------------------------------------
dcfreefall01
dcfreefall01
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 3
Ok, Here is the SP with the problem. Maybe another set of Eyes can see what is wrong. I am getting multi-part identifier could not be bound on every field.
Any help would be great.
Thank you.

SELECT
jn.branch_no as [Branch #],
b.branch_name as [Branch Name],
Case When jn.install_flag='Y' Then
'Install'
Else
'Service'
End as [Install/Service],
jn.jobgl_id as [GL],
jt.descr as [Job Type],
ct.Descr as [Customer Type],
jn.billto_cust_no as [Cust No],
s.Sitetype_id as [Site Type],
s.cspart_no as [CS Partition],
s.servarea_id as [Service Area],
s.site_no as [Site No],
s.site_name as [Site Name],
s.site_addr1 as [Site Address],
s.site_addr2 as [Site Address 2],
s.City_name as [City],
s.state_id as [State],
s.zip_code as [Zip],
IsNull(e1.last_name,'None') as [Sales Person],
IsNull(e.last_name,'None') as [Project Manager],
IsNull(e2.last_name,'None') as [Lead Employee],
jn.job_no as [Job No],
js.descr as [Job Status],
jn.change_date as [Closed Date],
jn.Servplan_id as [Service Plan],
--lak added next 4 rows 9/19/07
IsNull(jr.descr,'Install') as [Job Request],
IsNull(jn.cs_no,'None') as [CS No],

syst.descr as [System Type],
IsNull(jn.udf1,' ') as [WMS Proposal No],
IsNull(jn.udf2,' ') as [PO NTE],
IsNull(jn.udf4,' ') as [Service Type],

sum(jc.orig_direct_labor) as [Est. Labor],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_Direct_Labor
End) as [Labor],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_overhead
End) as [OverHead],
Sum(jc.orig_equip_cost) as [Est. Equip],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_Equip_Cost
End) as [Equipment],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_NonInventory_Cost
End) as [Non Inventory],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_SubContract
End) as [Sub-Contract],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_Misc_Cost
End) as [Misc],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_Permit_Cost
End) as [Permit],
sum( Case when ac.seqno <> 0 then
0
Else
ac.Act_hours
End) as [Actual Hours]
,Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_Total_Cost
End) as [Actual Total Cost],
Sum(Case When ac.seqno<>0 Then
0
Else
jc.rev_Total_Cost
End) as [Revised Total Cost],
Sum(Case When jc.rev_total_Cost = 0 Then
0
Else
Case When ac.seqno<>0 Then
0
Else
100*((ac.act_Total_Cost-jc.rev_Total_Cost)/jc.rev_Total_Cost)
End
End) as [Var%],
Sum(Case When ac.seqno<>0 Then
0
Else
jc.Orig_Total_Cost
End) as [Original Total Cost],
Sum(Case When jc.Orig_Total_Cost = 0 Then
0
Else
Case When ac.seqno<>0 Then
0
Else
100*((ac.act_Total_Cost-jc.Orig_Total_Cost)/jc.Orig_Total_Cost)
End
End) as [Var%],
Sum(Case When ac.seqno<>0 Then
0
Else
ac.act_Total_Price
End) as [Net Price],
Sum(Case When ac.Act_Total_Price = 0 Then
0
Else
Case When ac.seqno<>0 Then
0
Else
100*((ac.act_Total_Price-ac.act_Total_Cost)/ac.act_Total_Price)
End
End) as [Margin]
,Sum(Case When ac.seqno<>0 Then
0
Else
Case When
Case When ac.seqno<>0 Then
0
Else
ac.act_direct_labor
End = 0 And
Case When ac.seqno<>0 Then
0
Else
ac.act_equip_cost
End = 0 And
Case When ac.seqno<>0 Then
0
Else
IsNull(ac.act_misc_cost,0)+IsNull(ac.act_noninventory_cost,0)+IsNull(ac.act_overhead,0)+IsNull(ac.act_permit_cost,0)+IsNull(ac.act_subcontract,0)
End = 0 Then
0
Else
Case When jh.disc_id is null Then
jc.rev_total_price
Else
Case When substring(jh.disc_id,1,3)='REF' OR substring(jh.disc_id,1,3)='IPB' Then

jc.rev_total_price+jh.disc_amt
Else
jc.rev_total_price
End
End
End
End) as [Contract Price],


IsNull(SWR.WIPAmount,0) as [Previous WIP Revenue]

,Case when isNull(SWR.WIPAmount,0) < 0 Then
------------------------ Start of Contract Price --------------------------------------
(Sum(Case When ac.seqno<>0 Then
0
Else
Case When
Case When ac.seqno<>0 Then
0
Else
ac.act_direct_labor
End = 0 And
Case When ac.seqno<>0 Then
0
Else
ac.act_equip_cost
End = 0 And
Case When ac.seqno<>0 Then
0
Else
IsNull(ac.act_misc_cost,0)+IsNull(ac.act_noninventory_cost,0)+IsNull(ac.act_overhead,0)+IsNull(ac.act_permit_cost,0)+IsNull(ac.act_subcontract,0)
End = 0 Then
0
Else
Case When jh.disc_id is null Then
jc.rev_total_price
Else
Case When substring(jh.disc_id,1,3)='REF' OR substring(jh.disc_id,1,3)='IPB' Then
jc.rev_total_price+jh.disc_amt
Else
jc.rev_total_price
End
End
End
End)
------------------------ End of Contract Price ----------------------------------------
- --(Minus)
------------------------ Start of Progress Billing -------------------------------------
(Sum(IsNull(ac.progress_bill_amt,0))+
Sum(Case When substring(jh.disc_id,1,3)='IPB' Then
Case When ac.seqno>0 Then
0
Else
IsNull(jh.disc_amt,0)
End
Else
0
End)
------------------------ End of Progress Billing --------------------------------------
- --(Minus)
abs(isNull(SWR.WIPAmount,0))))
Else
------------------------ Start of Contract Price --------------------------------------
(Sum(Case When ac.seqno<>0 Then
0
Else
Case When
Case When ac.seqno<>0 Then
0
Else
ac.act_direct_labor
End = 0 And
Case When ac.seqno<>0 Then
0
Else
ac.act_equip_cost
End = 0 And
Case When ac.seqno<>0 Then
0
Else
IsNull(ac.act_misc_cost,0)+IsNull(ac.act_noninventory_cost,0)+IsNull(ac.act_overhead,0)+IsNull(ac.act_permit_cost,0)+IsNull(ac.act_subcontract,0)
End = 0 Then
0
Else
Case When jh.disc_id is null Then
jc.rev_total_price
Else
Case When substring(jh.disc_id,1,3)='REF' OR substring(jh.disc_id,1,3)='IPB' Then
jc.rev_total_price+jh.disc_amt
Else
jc.rev_total_price
End
End
End
End)
------------------------ End of Contract Price ----------------------------------------
- --(Minus)
sum(isNull(SWR.WIPAmount,0)))
End as [Net $ Earned],



Sum(IsNull(ac.progress_bill_amt,0))+
Sum(Case When substring(jh.disc_id,1,3)='IPB' Then
Case When ac.seqno>0 Then
0
Else
IsNull(jh.disc_amt,0)
End
Else
0
End) as [Progress Billing]
,jn.comment as [Comment]


FROM
dfm_job_no_cons jn with (nolock)
Left outer join job_actual_cost ac with (nolock) on jn.origjob = ac.job_no
Left outer join job_type jt with (nolock) on jn.jobtype_id = jt.jobtype_id
Left outer join job_status js with (nolock) on jn.jobstat_id = js.jobstat_id
Left outer join job_header_discount jh on jn.origjob = jh.job_no
Left outer join customer c with (nolock) on jn.billto_cust_no = c.cust_no
Left outer join customer_type ct with (nolock) on c.cusType_id = ct.cusType_id
Left outer join site s with (nolock) on jn.site_no = s.site_no
Left outer join job_cost jc with (nolock) on jn.origjob = jc.job_no
Left outer join employee e with (nolock) on jn.sales_emp_no = e.emp_no
Left outer join employee e1 with (nolock) on c.sales_emp_no = e1.emp_no
Left outer join employee e2 with (nolock) on jn.LeadEmployee = e2.emp_no
Left outer join branch b with (nolock) on jn.branch_no = b.branch_no
Left outer join site_type st with (nolock) on s.sitetype_id = st.sitetype_id
Left outer join system_type syst with (nolock) on jn.systype_id = syst.systype_id
Left outer join job_request jr with (nolock) on jn.jobreq_id = jr.jobreq_id
Left Outer Join (Select swr1.jobno,swr1.wipamount
from DPC_SavedWipRevenue swr1 with(nolock)
where swr1.datesaved = (Select Max(swr2.datesaved)
from DPC_SavedWipRevenue swr2 with(nolock)
where swr1.jobno = swr2.jobNO)) SWR on SWR.jobNO = jn.job_no

WHERE
jn.branch_no in (6,7) and
js.jobstat_id = 'C' AND
jn.change_date >= '08/01/2009 00:00:00' AND
jn.change_date <= '09/05/2009 23:59:59'
And (jn.install_flag In ('N'))

Group By jn.branch_no,
b.branch_name,
Case When jn.install_flag='Y' Then
'Install'
Else
'Service'
End,
jn.jobgl_id,
jt.descr,
jn.billto_cust_no,
s.Sitetype_id,
s.cspart_no,
s.servarea_id,
s.site_name,
s.site_addr1,
s.site_addr2,
s.City_name,
s.state_id,
s.zip_code,
IsNull(e.last_name,'None'),
IsNull(e1.last_name,'None'),
IsNull(e2.last_name,'None'),
jn.job_no,
js.descr,
jn.change_date,
jn.Servplan_id,
--next 4 rows added by LAK 9/19/07
IsNull(jr.descr,'Install'),
IsNull(jn.cs_no,'None'),
syst.descr,
s.site_no,
IsNull(jn.udf1,' '),
IsNull(jn.udf2,' '),
IsNull(jn.udf4,' ')
,SWR.WIPAmount
,jn.comment
,ct.Descr
sgmunson
sgmunson
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17505 Visits: 4638
How about we at least see this in more readable form:


SELECT jn.branch_no as [Branch #],
b.branch_name as [Branch Name],
Case
When jn.install_flag='Y' Then 'Install'
Else 'Service'
End as [Install/Service],
jn.jobgl_id as [GL],
jt.descr as [Job Type],
ct.Descr as [Customer Type],
jn.billto_cust_no as [Cust No],
s.Sitetype_id as [Site Type],
s.cspart_no as [CS Partition],
s.servarea_id as [Service Area],
s.site_no as [Site No],
s.site_name as [Site Name],
s.site_addr1 as [Site Address],
s.site_addr2 as [Site Address 2],
s.City_name as [City],
s.state_id as [State],
s.zip_code as [Zip],
IsNull(e1.last_name,'None') as [Sales Person],
IsNull(e.last_name,'None') as [Project Manager],
IsNull(e2.last_name,'None') as [Lead Employee],
jn.job_no as [Job No],
js.descr as [Job Status],
jn.change_date as [Closed Date],
jn.Servplan_id as [Service Plan],
--lak added next 4 rows 9/19/07
IsNull(jr.descr,'Install') as [Job Request],
IsNull(jn.cs_no,'None') as [CS No],

syst.descr as [System Type],
IsNull(jn.udf1,' ') as [WMS Proposal No],
IsNull(jn.udf2,' ') as [PO NTE],
IsNull(jn.udf4,' ') as [Service Type],

Sum(jc.orig_direct_labor) as [Est. Labor],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_Direct_Labor
End) as [Labor],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_overhead
End) as [OverHead],
Sum(jc.orig_equip_cost) as [Est. Equip],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_Equip_Cost
End) as [Equipment],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_NonInventory_Cost
End) as [Non Inventory],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_SubContract
End) as [Sub-Contract],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_Misc_Cost
End) as [Misc],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_Permit_Cost
End) as [Permit],
Sum(Case
When ac.seqno <> 0 then 0
Else ac.Act_hours
End) as [Actual Hours],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_Total_Cost
End) as [Actual Total Cost],
Sum(Case
When ac.seqno<>0 Then 0
Else jc.rev_Total_Cost
End) as [Revised Total Cost],
Sum(Case
When jc.rev_total_Cost = 0 Then 0
Else Case
When ac.seqno<>0 Then 0
Else 100*((ac.act_Total_Cost-jc.rev_Total_Cost)/jc.rev_Total_Cost)
End
End) as [Var%],
Sum(Case
When ac.seqno<>0 Then 0
Else jc.Orig_Total_Cost
End) as [Original Total Cost],
Sum(Case
When jc.Orig_Total_Cost = 0 Then 0
Else Case
When ac.seqno<>0 Then 0
Else 100*((ac.act_Total_Cost-jc.Orig_Total_Cost)/jc.Orig_Total_Cost)
End
End) as [Var%],
Sum(Case
When ac.seqno<>0 Then 0
Else ac.act_Total_Price
End) as [Net Price],
Sum(Case
When ac.Act_Total_Price = 0 Then 0
Else Case
When ac.seqno<>0 Then 0
Else 100*((ac.act_Total_Price-ac.act_Total_Cost)/ac.act_Total_Price)
End
End) as [Margin],
Sum(Case
When ac.seqno<>0 Then 0
Else Case
When Case
When ac.seqno<>0 Then 0
Else ac.act_direct_labor
End = 0 And
Case
When ac.seqno<>0 Then 0
Else ac.act_equip_cost
End = 0 And
Case
When ac.seqno<>0 Then 0
Else IsNull(ac.act_misc_cost,0) + IsNull(ac.act_noninventory_cost,0) +
IsNull(ac.act_overhead,0) + IsNull(ac.act_permit_cost,0) + IsNull(ac.act_subcontract,0)
End = 0 Then 0
Else Case
When jh.disc_id is null Then jc.rev_total_price
Else Case
When substring(jh.disc_id,1,3)='REF' OR substring(jh.disc_id,1,3)='IPB'
Then jc.rev_total_price+jh.disc_amt
Else jc.rev_total_price
End
End
End
End) as [Contract Price],

IsNull(SWR.WIPAmount,0) as [Previous WIP Revenue],
------------------------ Start of Contract Price --------------------------------------
Case
When isNull(SWR.WIPAmount,0) < 0
Then (Sum(Case
When ac.seqno<>0 Then 0
Else Case
When Case
When ac.seqno<>0 Then 0
Else ac.act_direct_labor
End = 0 And
Case
When ac.seqno<>0 Then 0
Else ac.act_equip_cost
End = 0 And
Case
When ac.seqno<>0 Then 0
Else IsNull(ac.act_misc_cost,0) + IsNull(ac.act_noninventory_cost,0) +
IsNull(ac.act_overhead,0) + IsNull(ac.act_permit_cost,0) + IsNull(ac.act_subcontract,0)
End = 0 Then 0
Else Case
When jh.disc_id is null Then jc.rev_total_price
Else Case
When substring(jh.disc_id,1,3)='REF' OR substring(jh.disc_id,1,3)='IPB'
Then jc.rev_total_price+jh.disc_amt
Else jc.rev_total_price
End
End
End
End) - --(Minus)
------------------------ End of Contract Price ----------------------------------------

------------------------ Start of Progress Billing -------------------------------------
(Sum(IsNull(ac.progress_bill_amt,0)) +
Sum(Case
When substring(jh.disc_id,1,3)='IPB'
Then Case
When ac.seqno>0 Then 0
Else IsNull(jh.disc_amt,0)
End
Else 0
End) - --(Minus)
------------------------ End of Progress Billing --------------------------------------

abs(isNull(SWR.WIPAmount,0))))

------------------------ Start of Contract Price --------------------------------------

Else (Sum(Case
When ac.seqno<>0 Then 0
Else Case
When
Case
When ac.seqno<>0 Then 0
Else ac.act_direct_labor
End = 0 And
Case
When ac.seqno<>0 Then 0
Else ac.act_equip_cost
End = 0 And
Case
When ac.seqno<>0 Then 0
Else IsNull(ac.act_misc_cost,0) + IsNull(ac.act_noninventory_cost,0) + IsNull(ac.act_overhead,0) +
IsNull(ac.act_permit_cost,0) + IsNull(ac.act_subcontract,0)
End = 0 Then 0
Else Case
When jh.disc_id is null Then jc.rev_total_price
Else Case
When substring(jh.disc_id,1,3)='REF' OR substring(jh.disc_id,1,3)='IPB'
Then jc.rev_total_price + jh.disc_amt
Else jc.rev_total_price
End
End
End
End) - --(Minus)
------------------------ End of Contract Price ----------------------------------------

sum(isNull(SWR.WIPAmount,0)))
End as [Net $ Earned],

Sum(IsNull(ac.progress_bill_amt,0)) +
Sum(Case
When substring(jh.disc_id,1,3)='IPB'
Then Case
When ac.seqno>0 Then 0
Else IsNull(jh.disc_amt,0)
End
Else 0
End) as [Progress Billing],
jn.comment as [Comment]

FROM
dfm_job_no_cons jn with (nolock)
Left outer join job_actual_cost ac with (nolock) on jn.origjob = ac.job_no
Left outer join job_type jt with (nolock) on jn.jobtype_id = jt.jobtype_id
Left outer join job_status js with (nolock) on jn.jobstat_id = js.jobstat_id
Left outer join job_header_discount jh on jn.origjob = jh.job_no
Left outer join customer c with (nolock) on jn.billto_cust_no = c.cust_no
Left outer join customer_type ct with (nolock) on c.cusType_id = ct.cusType_id
Left outer join site s with (nolock) on jn.site_no = s.site_no
Left outer join job_cost jc with (nolock) on jn.origjob = jc.job_no
Left outer join employee e with (nolock) on jn.sales_emp_no = e.emp_no
Left outer join employee e1 with (nolock) on c.sales_emp_no = e1.emp_no
Left outer join employee e2 with (nolock) on jn.LeadEmployee = e2.emp_no
Left outer join branch b with (nolock) on jn.branch_no = b.branch_no
Left outer join site_type st with (nolock) on s.sitetype_id = st.sitetype_id
Left outer join system_type syst with (nolock) on jn.systype_id = syst.systype_id
Left outer join job_request jr with (nolock) on jn.jobreq_id = jr.jobreq_id
Left Outer Join (
Select swr1.jobno,swr1.wipamount
From DPC_SavedWipRevenue swr1 with(nolock)
Where swr1.datesaved = (
Select Max(swr2.datesaved)
From DPC_SavedWipRevenue swr2 with(nolock)
Where swr1.jobno = swr2.jobNO)) SWR on SWR.jobNO = jn.job_no

WHERE jn.branch_no in (6,7)
AND js.jobstat_id = 'C'
AND jn.change_date >= '08/01/2009 00:00:00'
AND jn.change_date <= '09/05/2009 23:59:59'
AND (jn.install_flag In ('N'))

Group By jn.branch_no,
b.branch_name,
Case
When jn.install_flag='Y' Then 'Install'
Else 'Service'
End,
jn.jobgl_id,
jt.descr,
jn.billto_cust_no,
s.Sitetype_id,
s.cspart_no,
s.servarea_id,
s.site_name,
s.site_addr1,
s.site_addr2,
s.City_name,
s.state_id,
s.zip_code,
IsNull(e.last_name,'None'),
IsNull(e1.last_name,'None'),
IsNull(e2.last_name,'None'),
jn.job_no,
js.descr,
jn.change_date,
jn.Servplan_id,
--next 4 rows added by LAK 9/19/07
IsNull(jr.descr,'Install'),
IsNull(jn.cs_no,'None'),
syst.descr,
s.site_no,
IsNull(jn.udf1,' '),
IsNull(jn.udf2,' '),
IsNull(jn.udf4,' '),
SWR.WIPAmount,
jn.comment,
ct.Descr



Steve
(aka smunson)
:-):-):-)

Steve
‌(aka sgmunson)
Smile Smile Smile
Health & Nutrition
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search