pivot

Query Transposing certain rows into column names

Hi all, I have a couple of tables which look like this Table 1 user_id | name ------------------------- x111 | Smith, James x112 | Smith, Jane etc.. Table 2 id | code | date | incident_code | user_id ----------------------------------------------------------------- 1 | 102008 | 10/2...

SQL Pivot on subset

I have the following result set: Type | Method | Amount Type1 Cash Amount Type1 Check Amount Type2 Cash Amount Type2 Check Amount Type3 Cash Amount Type3 Check Amount And I want to make it look like this: Type | Cash | Check Type1 Amount Amount Type2 Amount Amount Type3 Amount Amount How can ...

Using "Show values as" option in Excel 2007 pivot table when source is SSAS cube?

I have an Excel 2007 pivot table showing "Year" across the top and "Month" down the side. What I am trying to do is represent the values as "% Difference" from the same month of the previous year. (Ex. If Jan-07 is $100,000 and Jan-08 is $120,000, I would like Jan-08 to show '20%'). However, every time I try to do this (using the "Sh...

Row Col Transposition in SQL Server 2005/2000

In SQL Server 2005, I have a table say tbl_Info. There I have one column say Info. The values are as under Name1 Age1 Sex1 Name2 Age2 Sex2 ..... ..... ..... And the row values goes on like this. My question is how to make row col transposition. The desired output will be Name Age Sex Name1 Age1 Sex1 Name2 ...

How do I take the results of multiple selects and combine into one row

hello, I have a table that contains information for 4 electrical generators I would like to have the results of the four querys in one row. does any one have a suggestion. Thanks SELECT avg(KW) as GEN_101_AVG FROM genset WHERE (GenSetName like 'GEA3519') and GenDate >= '1 jan 2003 00:00:00' and GenDate < '1 feb 2003 ...

MS-Access pivot columns

I create an MS Access 2007 query where the same customer has multiple project and data appear like: 1 | Foo 1 | Bar 1 | Baz 2 | For 3 | Cad 3 | Cam and I want to transform it into something like 1 | Foo | Bar | Baz 2 | For | 3 | Cad | Cam | The goal is to create a spreadsheet view per customer (1,2,3) which can be read from word...

SQL simplify a characteristic function? or PIVOT tables?

I have this a Table with a bunch of dates and prices: Room Name, Price, Bookdate, etc And I can transform it like so: (which essentially flips the columns) SELECT availables.name, rooms.id, MAX(IF(to_days(availables.bookdate) - to_days('2009-06-13') = 0, availables.price, '')) AS day1, MAX(IF(to_days(availables.bookdate) - to_days...

How to output a column per group that an item is a member of?

Given this SQL Input Table GroupId Item 1 Fish 1 FishBowl 2 Fish 3 Fish How Can i derive this Output? Item IsInGroup1 IsInGroup2 IsInGroup3 Fish Y Y Y FishBowl Y N N Please note that the Number of Groups can be variable ...

need Sql query (may be pivot)

Hi guys, i have table like below , Product Name Price Date Apple 1.5 5/5/2009 Apple 3 5/6/2009 Apple 3.5 5/7/2009 Apple 2.5 5/8/2009 Apple 5.5 5/9/2009 Orange 10.5 5/5/2009 Orange 12.5 5/6/2009 Orange 7.5 5/7/2009 Orange 4....

SQL pivot using SQL Server 2005

I am looking for a solution to use pivot on two tables. My problem though, number/name of column & row headers exist as rows in third table. My third table looks like this: ID Name 1 Row1 1 Row2 1 Row3 2 Col1 2 Col2 2 Col3 My final solution should look like this: Col1 Col2 Col3 C...

'there are too many records to complete this operation' Excel Pivot Table Refresh

Does anyone have a resource that gives possible reasons for this error message in Excel. I've googled around and looks like lots of people encounter the message but no one replies with concrete suggestions for resolving. The actual source of data is an Excel list and is only 1000 rows long and a few users use this pivot table and refre...

SQL Function that returns dynamically pivotted data

Is it at all possible to have a table valued function in MSSQL that takes an attribute and generates an associated SQL statement with Pivot function? CREATE FUNCTION dbo.fnPivot (@EntityTypeID int) RETURNS TABLE AS BEGIN DECLARE @SQL varchar(MAX); DECLARE @COLS varchar(MAX); select @COLS=coalesce(@COLS+',','')+'['+Name+']'f...

Oracle SQL Query to Summarize Statistics, using GROUP BY

I have an Oracle table with data that looks like this: ID BATCH STATUS 1 1 0 2 1 0 3 1 1 4 2 0 That is, ID is the primary key, there will be multiple rows for each "batch," and each row will have a status code in the STATUS column. There are a bunch of other columns, but these are the important...

Rows to Columns using Sql Query

hi i have a table with columns as Cost Rate Repair 12 Repair 223 Wear 1000 Wear 666 Fuel 500 Repair 600 Fuel 450 Wear 400 Now i want this data as Repair Wear ...

Converting Rows to column

Hi, let's assume I have a table with columns such as Cost Rate Repair 12 Repair 223 Wear 1000 Wear 666 Fuel 500 Repair 600 Fuel 450 Wear 400 and I want this data as columns(Repair,Wear,Fuel) as Repa...

Web form data structure alternatives

Once I created a form builder where user could select any number of fields for a web form. The tool then produced a code snippet which user could copy in the JSP. The submitted form data was stored as a key-value pairs in the DB, so basically just two columns were required for the form specific data. If I remember right, the processing ...

How to get table-like query result on SQL Server 2005/8 ?

I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id, amount) And I want to read the data from accounts and present it in table-like view: owner currency1 currency2 currency3 1 0 0 0 2 10 20 30 3 0 5 10 Where owner is ID of accounts.ow...

Sql Server Row Concatenation

Hi all, I have a table (table variable in-fact) that holds several thousand (50k approx) rows of the form: group (int) isok (bit) x y 20 0 1 1 20 1 2 1 20 1 3 1 20 0 1 2 20 0 2 1 21 1 ...

How to generate Pivot table in ExcelSheet Programatically

I am required to generate a Pivot table in MS Excel(not in Open Office) dynamically as per the User's query. I am programing in java and MySql(DB),so cant use the windows or MS object directly that's why wana to use VbScript . This vbscript will contain data as well as orentation on the columns in Pivot fieldList .But can any body tell m...

SQL Unique Values Numbering Sequence for Pivot

For reporting purcposes, I need to Pivot results of a query that is unique on each record. My current statement is: SELECT * FROM Sales AS x WHERE (select count(*) from Sales where customer_name=x.customer_name and order_date>=x.order_date)<=5 ORDER BY customer_name, order_date, price; A sample of the Query output is: custo...