mxfrail
Yak Posting Veteran
84 Posts |
Posted - 2009-01-15 : 10:09:04
|
[code]CREATE PROCEDURE ASP_StatusReport@SalesRep int,@Range int,@All int ASIf @All = 1BeginSELECT tblclients.clientid, tblclients.dbaname, tblcontractdetail.psijobno as PSIJobNo, convert(varchar(10),tblContractDetail.InHomeDate, 101) as InHomeDate, convert(varchar(10),dbo.ASP_DueDate(min(tblcontractdetail.proddate), tblcontractdetail.franchiseid, Case When tblcontractDetail.artrecd = 1 and (tblcontractdetail.procnum = 0 or tblcontractdetail.procnum is null) then 2 else tbljobprocessmappings.aspnum end, tblcontractdetail.mailingno), 101) as DueDate, Case When tblcontractDetail.artrecd = 1 and tblcontractdetail.procnum = 0 then 2 else tbljobprocessmappings.aspnum end as AspNumFROM (tblClients INNER JOIN (tblContractDetail INNER JOIN tblContracts ON tblContractDetail.ContractID = tblContracts.ContractID) ON tblClients.ClientID = tblContracts.ClientID) Left JOIN tblJobProcessMappings ON tblContractDetail.ProcNum = TblJobProcessMappings.ProcNumWHERE tblcontractdetail.repid = @SalesRep and tblcontractdetail.status <> 'Invoiced' and tblContractDetail.InHomeDate between convert(varchar(10), getdate(), 101) and convert(varchar(10),DateAdd(Day, @Range, getdate()), 101)GROUP BY tblcontractdetail.psijobno, tblclients.clientid, tblclients.dbaname, tblcontractdetail.mailingno, tblcontractdetail.franchiseid, tbljobprocessmappings.aspnum, tblContractDetail.InHomeDate, tbljobprocessmappings.aspnum, tblcontractdetail.artrecd, tblcontractdetail.procnumOrder BY duedate asc, tblclients.dbanameEndELSEBeginSELECT tblclients.clientid, tblclients.dbaname, tblcontractdetail.psijobno as PSIJobNo, convert(varchar(10),tblContractDetail.InHomeDate, 101) as InHomeDate, convert(varchar(10),dbo.ASP_DueDate(min(tblcontractdetail.proddate), tblcontractdetail.franchiseid, Case When tblcontractDetail.artrecd = 1 and (tblcontractdetail.procnum = 0 or tblcontractdetail.procnum is null) then 2 else tbljobprocessmappings.aspnum end, tblcontractdetail.mailingno), 101) as DueDate, Case When tblcontractDetail.artrecd = 1 and tblcontractdetail.procnum = 0 then 2 else tbljobprocessmappings.aspnum end as AspNumFROM (tblClients INNER JOIN (tblContractDetail INNER JOIN tblContracts ON tblContractDetail.ContractID = tblContracts.ContractID) ON tblClients.ClientID = tblContracts.ClientID) left JOIN tblJobProcessMappings ON tblContractDetail.ProcNum = TblJobProcessMappings.ProcNumWHERE tblcontractdetail.repid = @SalesRep and tblcontractdetail.status <> 'Invoiced' and tblContractDetail.InHomeDate between convert(varchar(10), getdate(), 101) and convert(varchar(10),DateAdd(Day, @Range, getdate()), 101) and AspNum not in (2,4)GROUP BY tblcontractdetail.psijobno, tblclients.clientid, tblclients.dbaname, tblcontractdetail.mailingno, tblcontractdetail.franchiseid, tbljobprocessmappings.aspnum, tblContractDetail.InHomeDate, tbljobprocessmappings.aspnum, tblcontractdetail.artrecd, tblcontractdetail.procnumOrder BY duedate asc, tblclients.dbanameEndGO[/code]If I run the select statements individually manually put in numbers it works fine. But if I run it as say -exec asp_statusreport @SalesRep=191, @All=1, @Range=60orexec asp_statusreport @SalesRep=191, @All=0, @Range=60It runs the same values as if the If @All=1 portion of if statement is not working.Any help would be great. |
|