473,811 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cross tab or derived table

Hi all,

I have a table in this format

colname1 colname2 colname3
col1data1 col2data1 col3data1
col1data2 col2data2 col3data2
col1data3 col2data3 col3data3
col1data4 col2data4 col3data4

I want to display it in this format

colname1 col1data1 col1data2 col1data3 col1data4
colname2 col2data1 col2data2 col2data3 col2data4
colname3 col3data1 col3data2 col3data3 col3data4

Basically rotate it through 90 degrees clockwise and flip it over :)

I'm pretty sure this is done by using a crosstab query and or a
derived table or temp table. The problem is I use a crosstab query to
get the original data into the first format. I've been struggling
trying to get the ouptput into the second format for over a day now
and just can't seem to get it to work. Can anyone give me any pointers
on the general solution to this?

I hope this makes sense. Thanks for the help.
Jul 20 '05 #1
4 2015

"mirth" <co**********@y ahoo.co.uk> wrote in message
news:78******** *************** *@posting.googl e.com...
Hi all,

I have a table in this format

colname1 colname2 colname3
col1data1 col2data1 col3data1
col1data2 col2data2 col3data2
col1data3 col2data3 col3data3
col1data4 col2data4 col3data4

I want to display it in this format

colname1 col1data1 col1data2 col1data3 col1data4
colname2 col2data1 col2data2 col2data3 col2data4
colname3 col3data1 col3data2 col3data3 col3data4

Basically rotate it through 90 degrees clockwise and flip it over :)

I'm pretty sure this is done by using a crosstab query and or a
derived table or temp table. The problem is I use a crosstab query to
get the original data into the first format. I've been struggling
trying to get the ouptput into the second format for over a day now
and just can't seem to get it to work. Can anyone give me any pointers
on the general solution to this?

I hope this makes sense. Thanks for the help.


I must admit that I don't really follow your description. Perhaps you could
post a CREATE TABLE statement for your table, plus INSERT statements for
some sample data, and also the expected result set - that would be much
clearer than a narrative.

Simon
Jul 20 '05 #2
Hi

As Simon asked!! Please supply DDL (Create table) statements and example
data (as insert statements) with the required output from that data.

You may want to look at previous posts regarding crosstab queries and
Itzik's article at:
http://www.winnetmag.com/SQLServer/A...608/15608.html
John

"mirth" <co**********@y ahoo.co.uk> wrote in message
news:78******** *************** *@posting.googl e.com...
Hi all,

I have a table in this format

colname1 colname2 colname3
col1data1 col2data1 col3data1
col1data2 col2data2 col3data2
col1data3 col2data3 col3data3
col1data4 col2data4 col3data4

I want to display it in this format

colname1 col1data1 col1data2 col1data3 col1data4
colname2 col2data1 col2data2 col2data3 col2data4
colname3 col3data1 col3data2 col3data3 col3data4

Basically rotate it through 90 degrees clockwise and flip it over :)

I'm pretty sure this is done by using a crosstab query and or a
derived table or temp table. The problem is I use a crosstab query to
get the original data into the first format. I've been struggling
trying to get the ouptput into the second format for over a day now
and just can't seem to get it to work. Can anyone give me any pointers
on the general solution to this?

I hope this makes sense. Thanks for the help.

Jul 20 '05 #3
Ok. thanks guys. I have already read the below website. The current
status is something like this. There will be more columns in the final
table but it will give you an idea. It's very much a work in progress.

DROP TABLE #SummaryTempTab le
CREATE TABLE #SummaryTempTab le (
[GLD_ACCTNG_PER] INT,
[External Sales] decimal,
[Internal Sales] decimal,
[Mark Up] decimal
)

INSERT INTO #SummaryTempTab le
SELECT GLD_ACCTNG_PER,
SUM(CASE WHEN (ACT_GL_NO between '4000' and '4399') THEN GLD_Total
ELSE 0 END) as 'External Sales',
SUM(CASE WHEN ((ACT_GL_NO between '4400' and '4499') and (ACT_GL_NO
<> '4400')) THEN GLD_Total ELSE 0 END) as 'Internal Sales',
SUM(CASE WHEN (ACT_GL_NO = '4400') THEN GLD_Total ELSE 0 END) as
'Mark Up'
FROM FinancePeriod
WHERE ([coid] = 'SPL') AND (GLD_SSN_BRH = 'CUM') AND (GLD_ACCTNG_PER
like '2004%') AND ACT_GL_NO BETWEEN 4000 AND 9999
GROUP BY GLD_ACCTNG_PER

The select statement gives data like this....

Period External Sales Internal Sales Mark Up
200301 -1287015 -4006 -202543
200302 -1771901 -8053 -350049
200303 -1831843 -9412 -215212
200304 -1193717 -1824 -103048
200305 -1450486 -5807 -242358
I need the output to look like this....

200301 200302 200303 200304 200305
External Sales -1287015 -1771901 -1831843 -1193717 -1450486
Internal Sales -4006 -8053 -9412 -1824 -5807
Mark Up -202543 -350049 -215212 -103048 -242358

I hope this helps explain a little better what I'm trying to do.

"John Bell" <jb************ @hotmail.com> wrote in message news:<Ri******* ************@ne ws-text.cableinet. net>...
Hi

As Simon asked!! Please supply DDL (Create table) statements and example
data (as insert statements) with the required output from that data.

You may want to look at previous posts regarding crosstab queries and
Itzik's article at:
http://www.winnetmag.com/SQLServer/A...608/15608.html
John

"mirth" <co**********@y ahoo.co.uk> wrote in message
news:78******** *************** *@posting.googl e.com...
Hi all,

I have a table in this format

colname1 colname2 colname3
col1data1 col2data1 col3data1
col1data2 col2data2 col3data2
col1data3 col2data3 col3data3
col1data4 col2data4 col3data4

I want to display it in this format

colname1 col1data1 col1data2 col1data3 col1data4
colname2 col2data1 col2data2 col2data3 col2data4
colname3 col3data1 col3data2 col3data3 col3data4

Basically rotate it through 90 degrees clockwise and flip it over :)

I'm pretty sure this is done by using a crosstab query and or a
derived table or temp table. The problem is I use a crosstab query to
get the original data into the first format. I've been struggling
trying to get the ouptput into the second format for over a day now
and just can't seem to get it to work. Can anyone give me any pointers
on the general solution to this?

I hope this makes sense. Thanks for the help.

Jul 20 '05 #4

Thanks guys but I sussed it. I went back to the drawing board and redone
the #temp table differently.

Appreciate the help though.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7512
by: Tim Pascoe | last post by:
I am using the Dynamic Cross-Tab code supplied in an article from SQL Server Magazine (http://www.winnetmag.com/SQLServer/Article/ArticleID/15608/15608.html). I modified the script to generate a temp table inside the stored procedure, and then use this temp table as the source for the cross-tab. However, the problem seems to be that the dynamic SQL string generated by the script is longer than what can be stored in the @SQL variable. The...
0
419
by: mirth | last post by:
Ok. thanks guys. I have already read the above website. The current status is something like this. There will be more columns in the final table but it will give you an idea. It's very much a work in progress. DROP TABLE #SummaryTempTable CREATE TABLE #SummaryTempTable ( INT, decimal, decimal, decimal
2
3558
by: Keith B via SQLMonster.com | last post by:
Hi! I want to return a derived table along with 4 simple tables in a stored procedure as follows: Input parameter: @FtNum (==Order Number, selects one Order and all associated data) Table 1: Orders Table 2: Items
2
2273
by: Peter Bär | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived classes? f.i. ive got a class dbobject i project "Basesupport", compiles to Basesupport.dll. From dbobject i derive about 100 classes, thy all are located in Project
0
1601
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone can help me ... My environment: VS 2003 v7.1.3088, Win2K v5.0.2195 SP3, IE6 v6.0.2800.1106 browser. I have a class (C3Menu) derived from WebControl, with a property (MenuItems) that is a collection of menu items. The collection property is...
10
1411
by: Julia | last post by:
Hi Please can someone explain this behaviour: I have a MustInherit Base class and a Derived class that Inherits Base and Shadows a method in the base class. If I Dim a variable of type Derived and New it as Derived the code in the Derived class is called. However, if I Dim the variable as type Base but New it as type Derived the Base class code is called - I would expect the code in
1
2600
by: Ruediger Herrmann | last post by:
Hello again, as I am new to PostgreSQL (great pice of softwork btw) this probably won't be the last question. I access PostgreSQL from Java via the PostgreSQL JDBC driver. I am currently building a little framework that provides basic CRUD operations by mapping class properties to database columns. All my primary keys are artificial and built by sequences (datat type bigserial). Now I need to (re-)read the row that was...
0
344
by: jerstlouis | last post by:
I'm hoping to generate some interest in the Ecere SDK which is the result of many years of software development. With the Ecere SDK, you can: Build Cross Platform GUI Applications: Develop applications once, deploy them on all platforms alongside a lightweight runtime environment.
13
4939
by: Rahul | last post by:
Hi Everyone, I was just playing around virtual functions and landed up with the following, class Base1 { public: virtual void sample() { printf("base::sample\n");
0
9726
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10384
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6887
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.