Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8823273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:18:44+00:00 2026-06-14T06:18:44+00:00

I’m a newb to both ASP.NET and Oracle SQL. I’m attempting to create one

  • 0

I’m a newb to both ASP.NET and Oracle SQL. I’m attempting to create one long SQL string (using UNION ALL) and then pass the string to a Data Handler class that takes care of the rest. The problem certainly exists in my SQL string.

Here is the first section of my code, which runs flawlessly:

sql = "SELECT 'DCS - HCA (81)', HCA_SENT_DCS, HCA_VALID_DCS, HCA_SUSPEND_DCS, HCA_REJECTED_DCS,"
sql &= " SUM(HCA_VALID_DCS + HCA_SUSPEND_DCS + HCA_REJECTED_DCS) As ""Total Returned"","
sql &= " RESOLVED_CNT, SUM(HCA_REJECTED_DCS - RESOLVED_CNT) As ""To Do"""
sql &= " FROM HUB_CDI_CONTROL_NBRS WHERE REPORT_DATE = :0 "
_param.Add(dateSelected.ToString("dd-MMM-yyyy"))
sql &= " GROUP BY HCA_SENT_DCS, HCA_VALID_DCS, HCA_SUSPEND_DCS, HCA_REJECTED_DCS,"
sql &= " RESOLVED_CNT"

However, when I try to UNION this SQL with another SELECT statement, I get the following exception:

ORA-00933: SQL command not properly ended

Here is the full code:

sql = "SELECT 'DCS - HCA (81)', HCA_SENT_DCS, HCA_VALID_DCS, HCA_SUSPEND_DCS, HCA_REJECTED_DCS,"
sql &= " SUM(HCA_VALID_DCS + HCA_SUSPEND_DCS + HCA_REJECTED_DCS) As ""Total Returned"","
sql &= " RESOLVED_CNT, SUM(HCA_REJECTED_DCS - RESOLVED_CNT) As ""To Do"""
sql &= " FROM HUB_CDI_CONTROL_NBRS WHERE REPORT_DATE = :0 "
sql &= " GROUP BY HCA_SENT_DCS, HCA_VALID_DCS, HCA_SUSPEND_DCS, HCA_REJECTED_DCS,"
sql &= " RESOLVED_CNT"

sql &= " UNION ALL"

sql &= "SELECT 'SFDC - HCA (82)', HCA_SENT_SFDC, HCA_VALID_SFDC, HCA_SUSPEND_SFDC, HCA_REJECTED_SFDC,"
sql &= " SUM(HCA_VALID_SFDC + HCA_SUSPEND_SFDC + HCA_REJECTED_SFDC) As ""Total Returned"","
sql &= " RESOLVED_CNT, SUM(HCA_REJECTED_SFDC - RESOLVED_CNT) As ""To Do"""
sql &= " FROM HUB_CDI_CONTROL_NBRS WHERE REPORT_DATE = :0 "
sql &= " GROUP BY HCA_SENT_SFDC, HCA_VALID_SFDC, HCA_SUSPEND_SFDC, HCA_REJECTED_SFDC,"
sql &= " RESOLVED_CNT"

_param.Add(dateSelected.ToString("dd-MMM-yyyy"))
_DH.TheSQL = sql
_DT = _DH.GetTableWithParameters(_param.ToArray)

I am concerned with two parts of this code:

  1. Am I correctly calling the _param.Add() function? Since I’m referencing the parameter twice, using :0, do I only have to use the _param.Add() function once?

  2. I feel that I’m incorrectly using the GROUP BY syntax. Oracle yelled at me when I tried to run queries without using GROUP BY, but I’m unsure if I’m using them correctly. Essentially, I just added each column I SELECTed to GROUP BY

Otherwise, I am sure there are other errors I am missing. Please help!

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:18:45+00:00Added an answer on June 14, 2026 at 6:18 am
    sql &= " UNION ALL"
    sql &= "SELECT 'SFDC - HCA (82)', HCA_SENT_SFDC, HCA_VALID_SFDC, HCA_SUSPEND_SFDC, HCA_REJECTED_SFDC,"
    

    Results in, somewhere in the middle:

    ... UNION ALLSELECT 'SFDC - HCA (82)', HCA_SENT_SFDC, ...
    

    Note: “UNION ALLSELECT“


    The full code with other fixes. I don’t believe you actually wanted to GROUP BY, to add/subtract, you DON’T need the SUM() function. To be valid in a UNION ALL, all columns of the first part must be named/aliased.

    sql = "SELECT 'DCS - HCA (81)' Title, HCA_SENT_DCS, HCA_VALID_DCS, HCA_SUSPEND_DCS, HCA_REJECTED_DCS,"
    sql &= " HCA_VALID_DCS + HCA_SUSPEND_DCS + HCA_REJECTED_DCS As ""Total Returned"","
    sql &= " RESOLVED_CNT, HCA_REJECTED_DCS - RESOLVED_CNT As ""To Do"""
    sql &= " FROM HUB_CDI_CONTROL_NBRS WHERE REPORT_DATE = :0 "
    sql &= " UNION ALL "
    sql &= "SELECT 'SFDC - HCA (82)', HCA_SENT_SFDC, HCA_VALID_SFDC, HCA_SUSPEND_SFDC, HCA_REJECTED_SFDC,"
    sql &= " HCA_VALID_SFDC + HCA_SUSPEND_SFDC + HCA_REJECTED_SFDC As ""Total Returned"","
    sql &= " RESOLVED_CNT, HCA_REJECTED_SFDC - RESOLVED_CNT As ""To Do"""
    sql &= " FROM HUB_CDI_CONTROL_NBRS WHERE REPORT_DATE = :1 "
    
    _param.Add(dateSelected.ToString("dd-MMM-yyyy"))
    _param.Add(dateSelected.ToString("dd-MMM-yyyy"))  ' 2nd one
    _DH.TheSQL = sql
    _DT = _DH.GetTableWithParameters(_param.ToArray)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.