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
Solved

SQL Formula Syntax

Posted on 2004-08-04
2
5,835 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

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

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
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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 the fundamental information of how to create a table.

860 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