?
Solved

Amend a union query, to include Having/Where statement

Posted on 2008-10-24
5
Medium Priority
?
235 Views
Last Modified: 2012-05-05
Hello, I have the following code which I have attached and in the 2nd table called "ledger_current_irb_balances" there is a field called "cust_type_code"
I want to change the syntax so it doesn't pull across records with the world
*Internal* in cust_type_code field.

Can some change the code for this to work?

Thanks
SELECT 
ccs.figures AS rr, 
sum(remain_to_roll) AS remain, 
sum(month_end_debt)-sum(remain_to_roll) AS sixty_plus, 
sum(month_end_debt) AS month_end, 
sum(ninety_plus) AS over_ninety
 
FROM 
ledger_current_icoms_balances l_bal 
 
 
INNER JOIN 
 
cht_collections_stuff ccs 
ON l_bal.c_c_c = ccs.index_field
 
GROUP BY 
ccs.figures
 
 
 
UNION ALL SELECT
 
ccs.figures as rr, 
sum(remain_to_roll) AS remain, 
sum(0-remain_to_roll+month_end_debt) AS sixty_plus,
sum(month_end_debt) AS month_end, 
sum(ninety+onetwenty) AS over_ninety,
 
 
FROM
ledger_current_irb_balances l_bal
 
INNER JOIN
cht_collections_stuff ccs
ON
l_bal.c_c_c = ccs.index_field
 
 
GROUP BY
ccs.figures

Open in new window

0
Comment
Question by:ShockUK
[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
  • 3
  • 2
5 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 22794624
INNER JOIN
cht_collections_stuff ccs
ON
l_bal.c_c_c = ccs.index_field
Where 1_bal.cust_type_code= chr(42) & "Internal" & chr(42)

(I am assuming you mean "*Internal*" literally and you are not using * as a wildcard.)
0
 

Author Comment

by:ShockUK
ID: 22795361
I created the changes as below, but when I run the syntax I get the following error:

The SELECT statement includes a reserved word or an argument name that is misspelled or missing,
or the punctuation is incorrect
SELECT 
ccs.figures AS rr, 
sum(remain_to_roll) AS remain, 
sum(month_end_debt)-sum(remain_to_roll) AS sixty_plus, 
sum(month_end_debt) AS month_end, 
sum(ninety_plus) AS over_ninety
 
FROM 
ledger_current_icoms_balances l_bal 
 
 
INNER JOIN 
 
cht_collections_stuff ccs 
ON l_bal.c_c_c = ccs.index_field
 
GROUP BY 
ccs.figures
 
 
 
UNION ALL SELECT
 
ccs.figures as rr, 
sum(remain_to_roll) AS remain, 
sum(0-remain_to_roll+month_end_debt) AS sixty_plus,
sum(month_end_debt) AS month_end, 
sum(ninety+onetwenty) AS over_ninety,
 
 
FROM
ledger_current_irb_balances l_bal
 
INNER JOIN
cht_collections_stuff ccs
ON
l_bal.c_c_c = ccs.index_field
Where l_bal.cust_type_code= chr(42) & "Internal" & chr(42)
 
 
GROUP BY
ccs.figures;

Open in new window

0
 
LVL 77

Expert Comment

by:peter57r
ID: 22795869
You need to be sure that there is a space between _field and Where (lines 37 & 38)
0
 

Author Comment

by:ShockUK
ID: 22811392
100% sure there is a space there, also a carriage return
0
 
LVL 77

Accepted Solution

by:
peter57r earned 1500 total points
ID: 22812053
How are you running this?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

764 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