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

  • SEARCH
  • Home
  • 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 8695541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:03:50+00:00 2026-06-13T01:03:50+00:00

I have three select queries which return total records , succesful records and failure

  • 0

I have three select queries which return total records , succesful records and failure records from same table based on different where clauses . I want to join the result of all these statements into one table in order to make my stored procedure but the resulting table shall have three different columns for cdr , success , failure

SELECT Count(*) AS cdr 
FROM   ABC AS c WITH (NOLOCK) 
WHERE  APPID IN( 1, 2 ) 
       AND CALLDATE = '2012-10-09' 

SELECT Count(*) AS success 
FROM   ABC AS d WITH (NOLOCK) 
WHERE  APPID IN( 44, 45 ) 
       AND CALLDATE = '2012-10-09' 
       AND HANGUPCODE IN ( 'man', 'mach' ) 

SELECT Count(*) AS fail 
FROM   ABC WITH (NOLOCK) 
WHERE  APPID IN( 44, 45 ) 
       AND CALLDATE = '2012-10-09' 
       AND HANGUPCODE NOT IN ( 'man', 'mach' ) 

Union gives out the result in one column so it won’t work . any other ideas

  • 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-13T01:03:51+00:00Added an answer on June 13, 2026 at 1:03 am

    Just wrap each select statement in parentheses, give each select statement an alias, and use SELECT at the top:

    SELECT 
      (select count(*) as cdr  
       from abc as c with (nolock) 
       where appid in(1,2)  and calldate = '2012-10-09'
      ) AS Column1,  
      (select count(*) as success  
       from abc as d with (nolock) 
       where appid in(44,45) and calldate = '2012-10-09' 
           and hangupcode in ('man', 'mach')
      ) AS Column2, 
      (select count(*) as fail  
       from abc  with (nolock) 
       where appid in(44,45) and calldate = '2012-10-09' 
           and hangupcode not in  ('man', 'mach')
      ) AS Column3
    

    Basically you’re treating each query as an individual column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three select boxes state,city and locality with the id's same as name
I have three table I need to query table 1,2 and 3 and select
I have a table with three columns, and two cells contain select boxes with
I have two seperate queries for my database which return search results for two
I have three individual queries that are used to select users dependent on the
I have three select boxes :- select1 select2 select3 , i am fetching data
I have a select element. <select class='cSelectType'> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> <option
I have the following HTML markup:- <select name=List1 id=l1> <option>One</option> <option>Two</option> <option>Three</option> <option>Four</option> <option>Five</option>
I have three tables in a database: Product table - +100000 entries Attribute table
I am developing a php script within the Joomla environment which queries the same

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.