473,473 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dependent CASE function of another CASE function in a SELECT statement

22 New Member
I would like to know the way that I can write a CASE function in a select statement that uses another variable that is created in the same SELECT statement using another CASE function. This is exacly what I am trying to do but obviusly gives me an error because is incorrect:

SELECT
CSV_SRV_QTY,
NET_PAID,
case when NET_PAID=0 THEN 0 ELSE CSV_SRV_QTY END AS ADJUNITS1,
CASE WHEN NET_PAID<0 AND ADJUNITS1>0 THEN -(ADJUNITS1) ELSE ADJUNITS1 END AS ADJUNITS2
FROM
CSV_MSTR
;

ADJUNITS1 runs fine but when add the second variable (ADJUNITS2) it produces an error.
Mar 14 '08 #1
1 2144
EORTIZ
22 New Member
NEVER MIND, HERE IS THE ANSWER. MAYBE SOMEONE IS INTERESTED
Expand|Select|Wrap|Line Numbers
  1. select units, total_paid, adjunits1,
  2. CASE WHEN total_paid<0 AND ADJUNITS1>0 THEN -(ADJUNITS1) ELSE ADJUNITS1 END AS ADJUNITS2 from
  3. (SELECT 
  4.     CSV_MSTR.CSV_SRV_QTY as units, 
  5.     CSV_MSTR.NET_PAID as total_paid,
  6.     case when NET_PAID=0 THEN 0 ELSE CSV_SRV_QTY END AS ADJUNITS1
  7.  
  8. FROM 
  9.     CSV_MSTR )
Mar 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: christian | last post by:
Hi, i'm getting no success, with my attempt displaying some pictures one after another for i.e. some seconds. null.jpg is a white site! Really thanks for any help, regards,Christian
2
by: Mark Mullins | last post by:
have code below: Function ClassColl(strClass As Variant, strColl As Variant) As String ' Comments : ' Parameters : strClass ' strColl ' Returns : String Description '...
4
by: Terencetrent | last post by:
I having been using Access '97/2002 for about 4 years now and have never really had the need or the time to learn visual basic. Well, I think the time has finally come. I need help with Visual...
4
by: deko | last post by:
When I loop through this function, it works fine until it hits End Function - then it jumps to End Select. Very strange... This behavior occurs when Case = 255. Any ideas why this is happening? ...
7
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
1
by: Hifni Shahzard | last post by:
Hi, I'm using VS.NET 2003, SQL Server 2000, Windows xp professional; My Question: Some of you might seen in some websites where it requests the Country in a dropdown. If the Country selected,...
8
by: | last post by:
Hello, This is gonna sound real daft, but how do I test a Select Case statement for variants of a theme? Here's a snippet of my code... Select Case sUsr Case "Guest", "TsInternetUser",...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.