Trying To Transpose And Collapse Data...

Oct 4, 2006

I'm relatively new to this, so bear with me here.  (SQL Server 2005 Express, Datatypes are all varchar, int or money, nothing crazy...)

I currently have a table (not designed by me...) which looks like this:

ProjectID            Months           Expenses





3214                JAN                    45.67

3214                 MAR                    56.78

1234                 JAN                     78.99

4567                  MAY                    43.56

 

And so on....  And I need this:

Project ID       Jan         Feb    Mar   Apr    May   Jun  etc....





3214              45.67                56.78

1234               78.99

4567                                                              43.56

 

I had attempted to do it using this code (really sloppy... I know.  Beginner's attempt...)





DECLARE @Months varchar(4)

DECLARE @Counter int

DECLARE @Rowcount int

EXEC @RowCount=dbo.ReturnRowCount

SET @Counter = 0

WHILE @Counter <= @RowCount

BEGIN

SET @Counter=@Counter+1

SET @Months=(SELECT Months FROM TestData WHERE RowNum=@Counter)

SELECT @Months

WHILE @Months='JAN'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Jan)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='FEB'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Feb)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='MAR'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Mar)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='APR'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Apr)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='MAY'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, May)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='JUN'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Jun)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='JUL'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Jul)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='AUG'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Aug)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='SEP'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Sep)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='OCT'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Oct)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='NOV'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Nov)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

WHILE @Months='DEC'

BEGIN

INSERT INTO SusansOutputTable (ProjectID, Dec)

SELECT ProjectID, Expenses FROM TestData WHERE @Counter=TestData.RowNum

SET @Months=''

END

SET @Months=''

END

SELECT RowNum, ProjectID, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec FROM SusansOutputTable







I also tried using IF statement instead of the imbedded WHILE statement and had the same result. What it's returning is 98,765 results of the same thing, with the exception of the last 25 rows, which return what I expected (which still needs to be collapsed...)  I know there HAS to be an easier way to do this, I'm afraid it might be a bit beyond me though, any help?

 

Ps.  ReturnRowCount function just returns the row count of the base table, assuming a rowid column with an IDENTITY int variable, which I can safely assume in this case.  Also, the counter seems to work fine, but something is wrong in my internal portion of the while loop I think...

          

View 3 Replies


ADVERTISEMENT

Transpose Data Using SQL

Jul 26, 2006

Hi Guys

I am having a bit of a delimma and am wondering if there is someone out there that could suggest how i could write a SQL statement that would alow me to return data in a certain way,

I have data as follows...

FIrst problemi is the Date in the LogDate COlumn is of Text Type not Date..

Second problem is i need to take this data and transform it to look like the table below

RCDIDEmployeeIDLogDateLogTimeTerminalIDInOut
411 07/23/200620:45:02iGuard# IN
421 07/23/200620:46:17iGuard# OUT
431 07/23/200620:48:08iGuard# IN
441 07/23/200620:48:18iGuard# OUT
451 07/23/200620:48:24iGuard# IN
461 07/23/200620:48:30iGuard# OUT
471 07/23/200620:48:36iGuard# IN
481 07/23/200620:48:41iGuard# OUT
501 07/23/200620:49:57iGuard# IN
511 07/23/200620:50:14iGuard# OUT
521 07/23/200620:59:34iGuard# IN
531 07/23/200620:59:40iGuard# OUT

Employee IDDateInOutIn OutTotalTimeIn
123/07/200620:3520:3620:3820:3900:02


Basicaly i need to transpose it..

If anyone has the sql or knows the sql on how to do this i would be very greatful

View 3 Replies View Related

Data Transpose - Need Help

Jan 20, 2004

Hi all,
Help me out, i am trying to get all values in Table A and insert into table B, i though of writing cursor. see endof the message



Table A:
CREATE TABLE [dbo].[M_SCANNEDSURVEY_AP] (
[M_CustomerSurveyID] [bigint] NULL ,
[SurveyID] [bigint] NULL ,
[LoadStatus] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[1] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[2] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[3] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[4] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[5] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[6] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[7] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[8] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[9] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[10] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[11] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[12] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DateSubmitted] [datetime] NULL
) ON [PRIMARY]
GO



Table B:
CREATE TABLE [dbo].[M_RESPONSE] (
[M_CustomerSurveyID] [bigint] NOT NULL ,
[SurveyID] [bigint] NOT NULL ,
[SeqNumber] [bigint] NOT NULL ,
[Response] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[DateSubmitted] [datetime] NULL
) ON [PRIMARY]
GO

I want to insert everything in table A to table B
M_CustomerSurveyID -> M_CustomerSurveyID
SurveyID -> SurveyID
I will hardcode insert 1,2,3,4,5,6,7,8,9,10,11,12 for sequence number
values of 1,2,3,4,5,6,7,8,9,10,11,12 -> Response
DateSubmitted -> DateSubmitted



Declare @Count_Scan INT

BEGIN
-- Get the count of scanned data in scanned data table with LoadStatus = N
SELECT @Count_Scan = COUNT(*) from M_SCANNEDSURVEY_APTEST where
LoadStatus = 'N'

IF @Count_Scan > 0
BEGIN
DECLARE ScanData_Cursor CURSOR FOR
SELECT * FROM M_SCANNEDSURVEY_AP WHERE LoadStatus = 'N'
OPEN ScanData_Cursor
FETCH NEXT FROM ScanData_Cursor
While (@@Fetch_Status <> -1)
Begin
If (@@Fetch_Status = -2)
Begin
FETCH NEXT FROM ScanData_Cursor
Continue
End
CLOSE ScanData_Cursor
DEALLOCATE ScanData_Cursor
END

SET @CountSuccess = 'Y'
END

View 4 Replies View Related

A Query-Transpose Of Data

Jul 23, 2005

I am supplying you with Sample Data:-Initial Classcode SampleSize Average------- ---------- -------------------------------ADK SSC 22 3.6800000000000002ADK TSC 17 2.7599999999999998ADK TSM 5 3.5499999999999998ANB FCA 31 3.23ANB FCB 50 3.0499999999999998ANB FCC 30 3.0899999999999999ANB SCA 35 3.02ANB SCB 9 3.4300000000000002ANB TCA 30 2.77ANB TCB 6 1.8799999999999999APG MCH 10 3.8300000000000001APG TSCH 9 4.21AUG FCC 30 3.5499999999999998AUG SCA 28 2.7800000000000002AUG SCB 29 3.4300000000000002AUG SCC 30 2.8999999999999999AUG TCA 30 2.8599999999999999AUG TCB 29 2.1200000000000001AVK TSP 12 3.6200000000000001BKK FS 32 2.52BKK TSM 5 3.3799999999999999BSK SSP 28 3.1200000000000001BSK TSP 12 3.0600000000000001------- ---------- -------------------------------These are the averages of teachers grouped by initial.Maximum 7 averages are related to each teacher.Ignore the column SampleSize.Using this output is it possible to get output like this:Initial Class1 Avg1 Class2 Avg2 Class3 Avg3 Class4 Avg4..ADKTSA 1.4 TSB 2.5 TSC 4.5 SSC 5.0..ANB SSA 1.4 SSB 2.5 NULL NULL NULL NULL..APG.........................AVK....................BKK....................BSK.....................Since the maximum class nos are 7, those having less than classes willcontain NULL in the class and average field.Is it possible to carry out this in single query?-Sameer

View 1 Replies View Related

Transact SQL :: Transpose Data Update

Jul 15, 2015

I have following sample data

I want this data updated to different table based on PK value relationship like below,

What shall I do to make such update ? Here is the sample script I want ot use

 DECLARE @Activity TABLE(PK BIGINT,Value1 NVARCHAR(10),Value2 NVARCHAR(10))
 INSERT INTO @Activity(PK) VALUES(1)
 INSERT INTO @Activity(PK) VALUES(2)
 INSERT INTO @Activity(PK) VALUES(3)

[Code] .....

View 11 Replies View Related

T-SQL (SS2K8) :: Transpose / Pivot Textual Data

Jan 19, 2015

In our contract management system, each contract has over 100 reference fields attached to it. These are all stored in single table with contract ID, reference GUID and value as the columns.

So you will have multiple rows for each contract....one for each of the reference fields and then the value attached to that reference.

I want to return the data so there is one row per contract with the reference fields as columns and the reference field values as the column data.

Can this be done using PIVOT as I have tried but not had any success?

View 6 Replies View Related

Transact SQL :: How To Transpose Data (Yearly Financials)

Jun 1, 2015

I have a simple table of yearly financials to transpose:

Year/Field       Financial1  Financial2 Financial3...
2014               1000000   2000000  3000000
2013               1000000   2000000  3000000
2012               1000000   2000000  3000000
....

The number of years available is dynamic. I would like to retrieve it as follows:
                     2014           2013        2012     
.....

Financial1     1000000   2000000  3000000
Financial2     1000000   2000000  3000000
Financial3     1000000   2000000  3000000$

What is the simplest way to achieve this?

View 7 Replies View Related

Transpose Source Data From A System Via Metadata Lookup Table Into Destination Table

Apr 1, 2014

I am stuck on finding a solution to transpose source data from a system via a metadata look-up table into a destination table. I need a method to transpose/pivot the source data into columns (which are by various data-types). The datatypes for each column are listed in a metadata table.

Source Data Table:

Table Name: Source

SrcID AGE City Date
01 32 London 01-01-2013
02 35 Lagos 02-01-2013
03 36 NY 03-01-2013

Metadata Table:

Table Name:Metadata

MetaID Column_Name Column_type
11 AGE col_integer
22 City col_character
33 Date col_date

Destination table:

The source data to be loaded into the destination table(as shown below):

Table Name: Destination

SrcID MetaID col_int col_char col_date
01 11 32 - -
01 22 - London -
01 33 - - 01-01-2013
02 11 35 - -
02 22 - Lagos -
02 33 - - 02-01-2013
03 11 36 - -
03 22 - NY -
03 33 - - 03-01-2013

View 7 Replies View Related

Collapse Textbox

Apr 17, 2008



Hi,

I have 3 textboxes going down.

box1
box2
box3

Is there a way to hide the box2 (with some condition) and shift up the box3 when displaying the result?
like this:

box1
box3

I know how to use the hidden property but it leave a blank space between box1 and box3.

FYI. I'm trying to do this in the PAGE HEADER section.

thank you for your help.
jib

View 4 Replies View Related

Collapse The Date Column?

Nov 6, 2014

Table created

declare @t table
(
Qtr VARCHAR(1000),visittype VARCHAR(1000),
CMSContractID VARCHAR(1000,memid VARCHAR(1000),
CarrierMemID VARCHAR(1000),HeadOfHouse VARCHAR(1000),
dobdatetime ,FullName VARCHAR(1000),minstartdt datetime,maxenddt datetime

[Code] ....

Expected output:

QtrvisittypeCMSContractIDmemidCarrierMemIDHeadOfHousedobFullNameminstartdtmaxenddt
06/01/2014 - 08/31/2014EDH8677CA140812115 1000000039546468-Apr-54TOM5-Jul-146-Jul-14
06/01/2014 - 08/31/2014EDH8677CA140812115 1000000039546468-Apr-54TOM9-Jul-149-Jul-14

View 3 Replies View Related

Expand All/Collapse All In Snapshots

Mar 28, 2007

I posted last year about getting and Expand All/Collapse All link working in reports, and it does work perfectly for on-demand reporting. I was able to get these working using the boolean report parameter and then the Jump to Report option going back to itself changing that parameter.



The issue that I have just discovered is that when a report with these Expand All/Collapse All links are in a report snapshot, clicking those links will cause it to re-render the report from the datasource at the time the link is clicked. This is an issue for one of the datasources we are using because the data is always changing, so when it goes back to re-render the counts and data returned are completely different then they were when the snapshot was first created. As time goes on the data will no longer even be in the datasource since it can only maintain 4 months of data.



Is there another way to get all detail groups to expand/collapse at once that does not require the report to be completely re-rendered from the datasource?

View 1 Replies View Related

Collapse Button In SQL Reports

Jun 23, 2007

I am working with SQL reporting services, I am getting the data dispalyed...

the only problem is that I am not able to collapse, ie (+) button next to the row header and the cloum header.

Can any one let me know, how to get that....

Thnks in adv.

View 1 Replies View Related

Query To Collapse Mutliple Rows

May 21, 2008

Hello -

I am having a difficult time trying to generate a result set that collapses multiple rows into one. However, I am also getting some of the columns that I am trying to SUM, to double their value.

I have two tables as:

Table 1
EmpID (int), AcctID (int), ActivityDate(datetime), Process (nvarchar 20), Cost (money)

Table 2
EmpID (int), AcctID (int), ActivityDate(datetime), Process (nvarchar 20), Duration (smallint)

Some sample data:
Table 1
501, 7998, 04-2-2008, Process1, $100
501, 7998, 04-2-2008, Process2, $75

Table 2
501, 7998, 04-2-2008, Process2, 3

Result i need is:
501, 7998, 04-02-2008, $175, 3

What I am getting is:
501, 7998, 04-02-2008, $175, 6

Any suggestions or help will be appreciated.

Thank you
- will

View 3 Replies View Related

The Collapse/toggling Effect In SSRS

May 27, 2008

Hi Guys,

I have created a report where I have Z-Index all set correctly, but I cannot see the desired effect of toggling as can be seen in the AdventureWorks sample of SalesOrder report that gets shipped with SSRS. What am I missing?

View 1 Replies View Related

Conditional Expand/Collapse Of Groups

Dec 21, 2007

Hi All,

I have a report that is grouping phone calls by "Category" (Outgoing, Incoming, Voicemail, etc). When the report is rendered, each category (along with totals) is shown and the details (each actual call) are hidden. Using toggling, I allow the user to burst open any category to view all of the call details.

I join the query for this report so that even if a category has 0 calls for the day, it is still shown. When expand a category with no calls I get a blank record (as I should, because there are no call details).

The question I have is ... Can I have the toggle be conditional? Can I have the ability to toggle thr group only when there are call details? Can I have the + to the left of the category name not be shown?


Thanks in advance for any help!
Merry Christmas!!!

-Matt

View 5 Replies View Related

Problems With Group Collapse/expand

Feb 27, 2007

On one of my reports, the +/- for expand/collapse of groups is reversed -- i.e. when the group is expanded it displays "+" and when the group is collapsed it displays "-". The display of the document map is correct.

Has anyone else had this problem?

thx

Helen

View 9 Replies View Related

Is There A Way To Redefine Expand/Collapse Sum Formula - Or Hide The Sum??

Feb 27, 2007

I have a relatively simple problem.

I have a db-query that returns quite a few rows which I must show in a table.
At initial load the report only shows the row group heading for the detailed data, and when clicked the detailed data for a group expands.

My problem is that reporting services assumes that when collapsed it should summarize everything in each column and display it.

Here is an illustration of the problem.

First the detailed view of my data (Notice the 5th and 6th rows which are simply the values in the 1st through 4th rows divided into groups - and the "Total" row shows the actual total for Row 1 Group Header:
[-] "Row 1 Group Header" "Detail data 1" "10" "Detail data 2" "10" "Detail data 3" "4" "Detail data 4" "6" "Row 1 group 1" "20" "Row 1 group 2" "10" "Total" "30"
The detailed view is just as I want it - no problems there.

However, when the detailed view is collapsed, reporting services calculates the sum for the column - which is 90 - not 30 as is the actual total:
[+] "Row 1 Group Header" "90"

Is there any way I can redefine the formula/insert filters used for calculating the "collapsed-total" for each column when the row is collapsed? Or maybe simply prevent it from showing a "collapsed-total" altogether? Or can you think of another way to structure the data so the "collapsed-totals" gives me the actual value (30)?

I thought about splitting the values into a column for each data-group, so that I'd have a column for the "Detail data n" values, a 2nd column for the "Row 1 group n" values and a 3rd column for the "Total" values - this would yield correct "collapsed-total" values. But is really a plan B - I really do not want to do that unless it is the only way out of my dilemma.

View 2 Replies View Related

Reporting Services :: Expand / Collapse All Sub-reports In SSRS

Jul 9, 2015

In my report i have more than 10 sub reports each should be displayed when we click on some label but my requirement is to expand all the sub reports at a time or collapse the sub reports.URL.....problem here is it is a genius solution working beautifully in my local machine but in the client server if i click on the Expand/Collapse radio button it is asking for the parameters again.

View 9 Replies View Related

Problem With Expand/collapse State Of Groups Between Renderings

Jun 11, 2007

Hi'

I have a problem with collapsing of groups. It seems that the reports saves the expand/collapse state of groups between renderings ... bug or feature?

In my report I have a dataset which contains some numerical data over time.

The report is designed to show data from a selected month as well as January to selected month.
A parameter is used to select the month.

The presentation looks like the following:
Company total
Department
Employee
Employee
...
Department
Emplyee
...
...
The employees have their initial state set to hidden, with their respective department as toggler.

This works perfectly ... within Visual Studio.
When I deploy this report to my web server strange things happens.

Fx
1) If I expand one department to see the data for the employees for may and then decide to look at data from another month.
2) I change the month parameter and click 'View report' to render the report again.
3) The report renders as it should. All departments are collapsed.
4) If I then expand some other department than before, both the newly selected department and the old one are expanded ... a behavior that is not that practical

It seems that the report saves the expand/collapse state for the groups between renderings. So when I click expand for the second time it expands the one I just clicked and the department which was expanded before rendering.

What to do?

View 3 Replies View Related

VS2005 Reportviewer - Documentmap - Collapse/Expand All Items

Jul 7, 2006

Is there a way to expand/collapse all items in the documentmap ?

I know there is an option DocumentMapCollapsed but this is to collapse/expand the documentmap panel. I would like to control the collapse state of the items into the document map ...





thanks in advane

View 3 Replies View Related

Hide Collapse All/Expand All Textbox For Groups When Printing Report

Feb 29, 2008

Hello all,

I have a report with some groups which can all be expanded/collapsed by clicking on a textbox with an action attached to it.
The example I used can be found here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=600583&SiteId=1

But I want to hide the row containing this textbox (or the textbox itself) on the actual printed report.
Is there any report item that can tell me if the report is in preview phase, or can it be solved in any other way?


Kind regards,
Dirk Holland

View 1 Replies View Related

Has Anyone Gotten A Tree View With Unknown Depth To Display With Collapse/expand At Every Level?

Dec 6, 2007

has anyone out there found a way to get the best of both recursive hierarchy and drill down in the same report, ie without needing to know how many levels there are in your hierarchy, still being able to report them like a tree view with collapse and expand capability at each level?

View 3 Replies View Related

How To Check Matrix Row Group's Visiblity Or Expand/Collapse Status In Program

Aug 7, 2007

Hi,

How do I programmatically check a row group's Visibility or Expand/Collapse flag in a matrix table? For example, I have a matrix table contains the following groups:

Row groups: Facility --> Category Type --> Category
Column groups --> year, quarter, month

I want to be able to programmatically update the table content if Category rows are not visible (Category Type row group is collapsed).

Thanks.

SouBee

View 3 Replies View Related

Is This A Transpose?

May 2, 2008

Hello,

I have a table that looks like this:

Customer Treas
------- -----
1010 Merch
1010 Price
1020 Merch
1030 Promo

And I need to add a period column so that the table looks like this.

Customer Treas Period
------- ----- ------
1010 Merch 1
1010 Merch 2
1010 Merch 3
1010 Price 1
1010 Price 2
1010 Price 3
1020 Merch 1
1020 Merch 2
1020 Merch 3
1030 Promo 1
1030 Promo 2
1030 Promo 3

etc. Of course there are 12 periods.

I'm thinking this is related to cross-tab or transpose function somehow? Once again I am clueless to the point I find it difficult to even research the problem on my own.

Hopefully this makes sense.

Thanks!

View 1 Replies View Related

Transpose Results

Apr 26, 2001

Besides using a cursor, is there a way to transpose a short result set to a comma delimited list?

For example, assume SELECT color FROM [tblColor] yields:

Red
Green
Blue
Black

My desired result is really:

Red, Green, Blue, Black

Any clues?

View 1 Replies View Related

Transpose Problem

Feb 25, 2004

Hello

I am currently importing an excel table into sql server in the form

date code header1 header2
2004 5AX num1 num2
2004 5AZ num3 num4
......

I am reading this into an sql table fine. However I want to convert its format into the following


date code field value
2004 5AX header1 num1
2004 5AX header2 num2
2004 5AZ header1 num3
2004 5AZ header2 num4
......


The number of header1, header2,..... is dynamic so I cannot hard code the number of headers there are.

Has anyone got any ideas. I have got some code already which will give me the number of headers there are but that Im afraid is as far as I have got before I get stuck

Thanks in advance for any help

Richard

View 2 Replies View Related

Transpose A Table

Mar 8, 2007

How to transpose a table. My table is like

taskid date1 hrs1 date2 hrs2 date3 hrs3 emp
1 3/3/2007 8.0 3/4/2007 8.5 3/5/2007 8.0 AAA
2 3/3/2007 8.0 3/4/2007 8.5 3/5/2007 8.0 BBB

I want the result as

date1 date2 date3
emp taskid hrs1 hrs2 hrs3

View 5 Replies View Related

SQL Transpose Table

Jul 23, 2005

I'm playing around with the following tables and need some advice.TablePeople (5000 records)peopleIDsexageraceTableExam (5000 records)examIDdatepeopleIDTableQuestions (5000 records)questionIDquestionFieldname (QFN0001,QFN0002,QFN0003, ... ,QFN5000)TableAnswers (25,000,000 records)examIDquestionIDanswerSQL Query Statement Needed!Query the database to return fields from TablePeople and TableAnswers(from 1 to 255 questionFieldnames)Example Query and return data from:ExamID,sex,age,race,QFN0001,QFN0002,QFN0003,QFN000 5,QFN0007,QFN0011I know how to join the tables and return the following recordsetExamID, sex, age, race, QuestionFieldName, AnswerID100001,M,40,White,QFN0001,0100001,M,40,White,QFN0002,5100001,M,40,White,QFN0003,6100001,M,40,White,QFN0005,3100001,M,40,White,QFN0007,5100001,M,40,White,QFN0011,4100002,M,55,White,QFN0001,1100002,M,55,White,QFN0002,4100002,M,55,White,QFN0003,3100002,M,55,White,QFN0004,4100002,M,55,White,QFN0007,5100002,M,55,White,QFN0011,6etc105000,M,48,White,QFN0001,5105000,M,48,White,QFN0002,4105000,M,48,White,QFN0003,6105000,M,48,White,QFN0005,3105000,M,48,White,QFN0007,4105000,M,48,White,QFN0011,5We would like the resulting table to look like the following:ExamID,sex,age,race,QFN0001,QFN0002,QFN0003,QFN000 5,QFN0007,QFN0011100001,M,40,White,0,5,6,3,5,4100002,M,55,White,1,4,3,4,5,6etc105000,M,48,White,5,4,6,3,4,5Any suggestions appreciated.Gregory S. MoyInformation Processing ConsultantEpiSense Research ProgramDepartment of Ophthalmology & Visual SciencesUniversity of Wisconsin - Madison

View 1 Replies View Related

Transpose In SSRS

Dec 11, 2007

Is there anything like transpose in SSRS.

The result of my t-sql queries gives me many columns and less rows
i.e there are four quaters as rows and there are around 10 columns like sales , customer , material ....

So if i can transpose columns to rows and rows to columns some how then the report will be more presentable according to me.

Can anyone please help me out.

View 1 Replies View Related

Table Transpose

Mar 30, 2007

Hi

I have a "transaction" table of diagnostic tests, each row consisting of one test performed on one person as follows:



Patient Test Time

ID ID of Test

--------------------------

1 1 May 1

1 2 May 1

1 4 May 2

2 5 etc.

3 1

3 3

4 4

4 2



I'd like to transpose this into a table with one row per patient, so I can then describe, for each patient, the sequence of tests that he or she had, e.g.



Patient T1 T2 T3 T4 T5 TEST_SEQUENCE

1 1 2 4 - - "1 2 4"

2 5 - - - - "5"

3 1 3 - - - "1 3"

4 4 2 - - - "4 2"



How do I do this in SQL, preferably without having to specify the maximum number of tests? (In a statistical package we use, this is called a table "reshape" operation)



Thanks in advance.



View 7 Replies View Related

Transpose Rows Into Columns

Oct 22, 2007

Any of you have code to transpose rows into columns in T-SQL 2000. For example I have the following table

ID type
1 A
1 B
2 A
2 C
2 D
etc,....




I want to tranpose

to some like

ID type
1 A,B
2 A,C,D
etc,...


or

ID type1 type2 type3
1 A B
2 A C D

etc,....


Really appreciate any input.

View 3 Replies View Related

Transpose Rows To Columns

Apr 23, 2008

I have the below table:
Pallet1 ItemA1
Pallet1 ItemB1
Pallet1 ItemC1
Pallet1 ItemD1
Pallet1 ItemE1
Pallet2 ItemA2
Pallet2 ItemB2
Pallet2 ItemC2
Pallet2 ItemD2


Would like to Transpose it to
Pallet 1 ItemA1 ItemB1 ItemC1 ItemD1 ItemE1
Pallet 2 ItemA2 ItemB2 ItemC2 ItemD2 NULL

Would be thankful for Any help.

View 2 Replies View Related

Transpose 1 Column To Rows

Jul 2, 2014

I am looking to transpose a row into multiple columns. I have a member's data who might be associated with multiple labs for that one member. Instead of having multiple records for that member, I would like to have one record per member with multiple rows for the lab data.

View 16 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved