473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pivot in SQL

I have query that returns results like the following:

request_id field_id field_value
12345 2 abc
12345 3 asdf
12345 11 10
12346 2 def
12346 3 asdf
12346 11 20

and so on.
I would like to display the results like this:

request_id field_2 field_3 field_11
12345 abc asdf 10
12346 def asdf 20

I tried the floowing "pivot" command in SQL 2005:

select request_id, field_id, field_value
from some_table
pivot (
field_value for field_id in (2, 3, 11)
)

but I keep getting this error:

Error in FROM clause: near 'FOR'.
Unable to parse query text.

Does anyone have any idea what I am doing wrong?
Thanks in advance.
Apr 9 '08 #1
1 1595
ck9663
2,878 Expert 2GB
I have query that returns results like the following:

request_id field_id field_value
12345 2 abc
12345 3 asdf
12345 11 10
12346 2 def
12346 3 asdf
12346 11 20

and so on.
I would like to display the results like this:

request_id field_2 field_3 field_11
12345 abc asdf 10
12346 def asdf 20

I tried the floowing "pivot" command in SQL 2005:

select request_id, field_id, field_value
from some_table
pivot (
field_value for field_id in (2, 3, 11)
)

but I keep getting this error:

Error in FROM clause: near 'FOR'.
Unable to parse query text.

Does anyone have any idea what I am doing wrong?
Thanks in advance.
Check the full syntax here

-- CK
Apr 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Prasad Patil | last post by:
Hi, I have created a report in excel, it uses Pivot tables. The excel has two sheets 1: Pivot ( Contains the Pivot Table) 2: Data (Data Requred to populate the pivot table I create an...
2
by: Rob | last post by:
I'm just getting around to using pivot tables and charts. I find the Pivot table interface to be INCREDIBLY frustrating. When I view a table in Design view, then choose Pivot table view, I get...
1
by: Grey | last post by:
I have created a asp.net form for user to input data. After input the data, user need to click a button to export the input data to excel for data analysis with excel pivot table function. is it...
2
by: Carl Gilbert | last post by:
Hi I have a math kinda problem where I'm trying to split some lines when two or more lines connect two shapes. The reason I am doing this is to make it clear that there are multiple lines...
3
by: Jerry K via DotNetMonster.com | last post by:
I'm creating a pivot table using vb.net and the data is from sqlserver (desktop). I have been successful at creating the pivot table, which includes a 'date' column field. I'd like to group the...
3
by: GoalieGW | last post by:
Does anyone know how to create a Pivot Chart at run-time? I have a database of meter readings that currently requires me to have 200 forms created so the user can enter date criteria and have a...
3
by: nikila | last post by:
Hi, I have to create excel pivot tables from vb.net. Already I am creating excel file using oledb connection. I want to use the same to create the excel pivot tables. Can anyone please help me...
9
by: PeteCresswell | last post by:
I've got something called "Reference Rates". The idea is that on a given day, we have various rates of return for various entities. e.g. Libor 3-month return, Libor 6-month return, US Treasury...
5
by: Pourya99 | last post by:
Hello, I have an Access Data Access Page which has a pivot table. The data source of the pivot table is a SQL database table. The data in the pivot table itself is not a problem. I have a text...
1
by: mld01s | last post by:
I really need help!!! I dont know if its possible to share pivot tables, or see pivot tables in other machines that the one where the tables were created. This is what happens: I created a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.