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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:34:53+00:00 2026-06-07T01:34:53+00:00

When I try to execute the query below, I get error Incorrect syntax near

  • 0

When I try to execute the query below, I get error

Incorrect syntax near the keyword ‘convert’

and I’m not sure where I made mistake. The data type for qty field is nchar so I used convert function for finding totals.

select column_date, [red] as red, [blue] as blue, [green] as green, [yellow] as yellow 
from
(select * from table1) as t1
pivot
(
sum(convert(int,qty)) 
For color in 
([red], [blue], [green], [yellow])
) as SumofQuantityforeachcolor

Here is the table

column_date | color | qty | supplier
1 June 2012 | red   | 2   | XY
1 June 2012 | red   | 1   | AB
1 June 2012 | blue  | 4   | CD
1 June 2012 | blue  | 1   | XY
2 June 2012 | yellow| 13  | CD
2 June 2012 | green | 45  | CD
2 June 2012 | blue  | 32  | AB
2 June 2012 | red   | 37  | XY
2 June 2012 | red   | 2   | XY
2 June 2012 | red   | 1   | AB
2 June 2012 | blue  | 4   | CD
3 June 2012 | red   | 1   | AB
3 June 2012 | blue  | 4   | CD
3 June 2012 | blue  | 1   | XY
3 June 2012 | yellow| 13  | CD
3 June 2012 | green | 45  | CD
3 June 2012 | blue  | 32  | AB

and so on…

  • 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-07T01:34:55+00:00Added an answer on June 7, 2026 at 1:34 am

    Don’t use select * in your sub query. List all columns you need and do the type cast in the field list instead of in the sum() function.

    The aggregate function in a pivot does not take an expression as an argument. You have to specify a column.

    <pivot_clause> ::=
            ( aggregate_function ( value_column [ [ , ]...n ]) 
            FOR pivot_column 
            IN ( <column_list> ) 
        )
    

    You are probably looking for something like this.

    select column_date, [red] as red, [blue] as blue, [green] as green, [yellow] as yellow 
    from (
         select column_date,
                color,
                cast(qty as int) as qty
         from table1
         ) as T
    pivot
         (
         sum(qty) 
         for color in ([red], [blue], [green], [yellow])
         ) as SumofQuantityforeachcolor
    

    SE-Data

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

Sidebar

Related Questions

I get the following error when I try and execute the code down below.
If I try to execute below query: EXEC sp_rename 'ENG_TEst.[ENG_Test_A/C_TYPE]', 'ENG_Test_AC_TYPE', 'COLUMN' I get
I'm trying to get the code below to work..... The error: ERRORSQLSTATE[42000]: Syntax error
When I try to execute my code, I'm getting an error dialog: 'Show Disassembly'
This is what I try to execute: CREATE TABLE order ( o_id INTEGER not
Okay, I'm getting this error when I try to execute this procedure. The thing
I am trying to get the sql query below to work but I am
I am using Hibernate on a JBoss server. I get the error below. The
When I try to execute this statement in Oracle SQL Developer 2.1 a dialog
I'm on ubuntu 10.04 when I try to execute a java program in a

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.