Unix Technical Forum

How To write An Sql Crosstable Select statment

This is a discussion on How To write An Sql Crosstable Select statment within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, would like to know how to write a crosstable select statment in sql server2000 where having: - ItemNumber, ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:23 AM
Joe Saliba
 
Posts: n/a
Default How To write An Sql Crosstable Select statment

Hi,

would like to know how to write a crosstable select statment in sql
server2000 where having:
- ItemNumber, ItemDescription, ItemColor, ItemSize as rows
- Stores as columns
- Qty * Netttc as value

from Table sales

thx

*** Sent via Developersdex http://www.developersdex.com ***
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:24 AM
John Bell
 
Posts: n/a
Default Re: How To write An Sql Crosstable Select statment

Hi

Posting DDL and example data and expected output helps to answer your query
more easily see http://www.aspfaq.com/etiquett*e.asp?id=5006

If you had a Items Table

CREATE TABLE Items ( ItemNumber int, Description varchar(50), Color
char(10), Size int )

CREATE TABLE SaleItems ( ItemNumber int, Store varchar(50), Qty int, Nettttc
decimal(8,3))

Then something like:

SELECT I.ItemNumber, I.Description, I.Color , I.Size
SUM(CASE WHEN S.Store = 'London' THEN S.Qty*S.Nettttc END) AS [London],
SUM(CASE WHEN S.Store = 'Paris' THEN S.Qty*S.Nettttc END) AS [Paris],
SUM(CASE WHEN S.Store = 'Madrid' THEN S.Qty*S.Nettttc END) AS [Madrid]
FROM Items I
LEFT JOIN SaleItems S ON I.ItemNumber = S.ItemNumber
GROUP BY I.ItemNumber, I.Description, I.Color , I.Size

may be something similar to what you want.


John

"Joe Saliba" <josephs73@hotmail.com> wrote in message
news:Vcofe.364$IN1.2255@news.uswest.net...
> Hi,
>
> would like to know how to write a crosstable select statment in sql
> server2000 where having:
> - ItemNumber, ItemDescription, ItemColor, ItemSize as rows
> - Stores as columns
> - Qty * Netttc as value
>
> from Table sales
>
> thx
>
> *** Sent via Developersdex http://www.developersdex.com ***



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:05 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com