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 8426731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:36:35+00:00 2026-06-10T04:36:35+00:00

I have Written a query which returns multiple column.Out of which One Column contains

  • 0

I have Written a query which returns multiple column.Out of which One Column contains repetitive entries.

FAULT_SHORT_NAME

ATM DOWN DUE TO LINK PROBLEM
ATM DOWN DUE TO LINK PROBLEM
ALL CASSETTES FAULTED
ALL CASSETTES FAULTED
ATM IS MARK DOWN
ATM IS MARK DOWN

Now I want to Modify My query in Such a way that it will show me Value Count as

ATM DOWN DUE TO LINK PROBLEM ALL CASSETTES FAULTED  ATM IS MARK DOWN
2                             2                         2

There Can be Different “FAULT_SHORT_NAME” Values so Cant Hard Code them.My Original Query is

      Select * From ATMStatus S Left Join ATM A on S.ATM=A.Code 
          Left Join EventMsg E On S.Fault=E.Code 
          Where A.ATMStatus=0 AND S.TicketBooked <> 0

FAULT_SHORT_NAME is Column of Table “EventMsg”

  • 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-10T04:36:36+00:00Added an answer on June 10, 2026 at 4:36 am

    It looks like you want a PIVOT since you want the values as columns instead of rows. there are two ways to do this either a Static or dynamic pivot.

    Static Pivot, you hard-code the values of the columns:

    SELECT *
    FROM
    (
        Select * 
        From ATMStatus S 
        Left Join ATM A 
            on S.ATM=A.Code 
        Left Join EventMsg E 
            On S.Fault=E.Code 
        Where A.ATMStatus=0 
            AND S.TicketBooked <> 0
    ) x
    PIVOT
    (
        count(*)
        for FAULT_SHORT_NAME in ([ATM DOWN DUE TO LINK PROBLEM], 
            [ALL CASSETTES FAULTED], [ATM IS MARK DOWN])
    ) p
    

    Dynamic Pivot, the columns are generated at run-time:

    DECLARE @cols AS NVARCHAR(MAX),
        @query  AS NVARCHAR(MAX)
    
    select @cols = STUFF((SELECT distinct ',' + QUOTENAME(FAULT_SHORT_NAME) 
                        from EventMsg
                        FOR XML PATH(''), TYPE
                        ).value('.', 'NVARCHAR(MAX)') 
                    ,1,1,'')
    set @query 
          = 'SELECT ' + @cols + ' from 
             (
                Select * 
                From ATMStatus S 
                Left Join ATM A 
                    on S.ATM=A.Code 
                Left Join EventMsg E 
                    On S.Fault=E.Code 
                Where A.ATMStatus=0 
                    AND S.TicketBooked <> 0
             ) x
             pivot 
             (
                count(*)
                for FAULT_SHORT_NAME in(' + @cols + ')
             ) p '
    
    execute(@query)
    

    Both will produce the same results. If you provide additional details about the tables and some sample data, then I could provide a more exact example.

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

Sidebar

Related Questions

I have written a query which involves joins and finally returns the below result,
I have written this query which returns a users friends and the friends on
I have written some code which sends queries to google and returns the query
I am working on SQLite and I have written a query which returns me
I have written method which should return string with data from select query, but
I have a query which returns to me results as follows: Race | Candidate
i have written insert query for my application to create new user with password,
I have written media query for 3 different dimensions. Intial style is for 320px
I have written a query to find similar ids based on tags from a
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,

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.