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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Statement 1

Status
Not open for further replies.

newmediaguy

Programmer
Mar 26, 2004
176
GB
Hi Guys

I have a problem with some SQL I have inherited....am better with ASP than SQL...

Anyway I need to add to this statement to compare two columns and if they match then display 0.00.

Code:
SELECT 
			  AgentCode
			, BranchName
			, ParkCode
			, TACode
			, BookingNumber
			, LeadName
			, dbo.Fn_FormatDate(BookDate,'dd/mm/yyyy') as BookDate
			, dbo.Fn_FormatDate(ArrivalDate,'dd/mm/yyyy') as ArrivalDate
			, dbo.Fn_FormatDate(PaymentDueDate,'dd/mm/yyyy') as PaymentDueDate
			, Deposit
			, Commission
			, GrossValue
			, NetBillings
			, PaidToDate
			, OutstandingAmount
			, CASE 	WHEN PaymentDueDate < ReportDate
					THEN GrossValue - Commission - PaidToDate
					ELSE DEPOSIT - PaidToDate
				END AS AmountDue
			, Season
			, ReportDate
			, dbo.Fn_FormatDate(PaymentDueDate,'dd/mm/yyyy') as PDATE
			, dbo.Fn_FormatDate(ArrivalDate,'dd/mm/yyyy') as ArrDate
			, AgentRef
			,CASE WHEN PaymentDueDate < GETDATE() THEN GrossValue - Commission - PaidToDate

/* This is where I need to comapare : 
Deposit and PaidToDate if they match display 0.00 in NewAmountDue
*/

 ELSE ISNULL(deposit,0) END AS NewAmountDue

Any pointers would be helpful.......in the mean time will keep beating google up...

Thanks

Glen

Glen
Conception | Execution
 
try this ..

Code:
CASE WHEN PaymentDueDate < GETDATE() THEN GrossValue - Commission - PaidToDate

 WHEN Deposit = PaidToDate THEN 0

 ELSE ISNULL(deposit,0) END AS NewAmountDue
end as NewAmountDue
 
Thanks

That worked perfectly, was trying with nested case statements that werent working as intended.

Many thanks

Glen

Glen
Conception | Execution
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top