Solved

SQL Formula Syntax

Posted on 2004-08-04
2
5,833 Views
Last Modified: 2008-01-09
I am trying to implement some logic in my SQL tables using formulas.
In this case, I am trying to do two comparison, neither of which seem to work:
1. I would like to test for a Non-Null Date field. I'm using Not IsNull(DatePaid), but it doesn't seem to work.
2. I would like to test for a text field equal to a value. I'm using [JobType] = 'Partner', but that doesn't seem to work either.

Here is the syntax of my whole statement currently (but it doesn't work):

convert(money, (case when ([JobType] = 'Partner Plus' and Not IsNull([DateCompleted])) then round(([TotalAmount] * [PartnerPlusPercent]),2) else 0 end),2)

Is this even possible? I can't find much on what is possible in these computed field formulas. Do I need to set up a trigger instead?

Thanks, Ted
0
Comment
Question by:tk3
2 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 500 total points
ID: 11722875
No trigger is needed, and there's nothing wrong with [JobType] = 'Partner Plus', but you need IS NOT NULL instead of NOT ISNULL().

Try this:

Convert(money, (
CASE WHEN ([JobType] = 'Partner Plus' AND [DateCompleted] IS NOT NULL)
THEN round(([TotalAmount] * [PartnerPlusPercent]),2)
ELSE 0 END),2)
0
 

Author Comment

by:tk3
ID: 11723038
Is it possible to nest the 'CASE' statements?
I tried do that and it doesn't seem to work. I'm not sure if I have a small error somewhere or if that is just impossible.

The statement I am trying is this:

Convert(money, (CASE WHEN ([DateCompleted] IS NOT NULL) THEN
(CASE WHEN ([JobType] = 'Partner) THEN round(([TotalRewardBase] * [PartnerPercent]),2)
ELSE round(([TotalRewardBase] * [PartnerPlusPercent]),2))
ELSE 0 END),2)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

831 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