?
Solved

SQL Formula Syntax

Posted on 2004-08-04
2
Medium Priority
?
5,838 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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…
Suggested Courses

770 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