Solved

SQL 2005 View.  How to calculate a view expression column with more details

Posted on 2007-11-14
1
420 Views
Last Modified: 2008-02-01
I am trying to further narrow down an expression in a view.  Below is the expression:

dbo.Payments.AmountPaid - (dbo.InvoiceDetails.Usage * dbo.InvoiceDetails.Price + ISNULL((dbo.InvoiceDetails.TRate / 100) * (dbo.InvoiceDetails.Price * dbo.InvoiceDetails.Usage), 0))

I want to take the above expression and make the outcome 0 if AmountPaid is 0.
Only when there is an amoutpaid is when I want to see the value else 0.

Thanks
0
Comment
Question by:mphillip85
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20282441
case when dbo.Payments.AmountPaid  = 0 then 0 else dbo.Payments.AmountPaid - (dbo.InvoiceDetails.Usage * dbo.InvoiceDetails.Price + ISNULL((dbo.InvoiceDetails.TRate / 100) * (dbo.InvoiceDetails.Price * dbo.InvoiceDetails.Usage), 0)) end
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question