🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.databases.ms-sqlserver
Article #52

Need help transforming results set format

#52
From: Brent Eubanks
Date: Thu, 24 Apr 1997 00:00
87 lines
1978 bytes

I have a query that generates a results set of the following format:


DAY CODE TOTAL
--- ---- -----
mon   A    5
tue   A   10
wed   A    7
fri   A   20
sat   A    5
mon   B   12
thu   B    3
fri   B   16
sat   B    9
sun   B   23
tue   C    5
wed   C   21
sat   C   17


I need to put it into the following format:

Day   A   B   C
---  --- --- ---
mon   5  12   0
tue  10   0   5
wed   7   0  21
thu   0   3   0
fri  20  16   0
sat   5   9  17
sun   0  23   0

Can anyone suggest a way to do this other than inserting each value
with an individual update statement?  (There are 21 values in this
sample set.  The real thing is much to big to do peicemeal.)



ALTERNATELY:

If my starting set look like this

DAY CODE TOTAL
--- ---- -----
mon   A    5
tue   A   10
wed   A    7
thu   A    0
fri   A   20
sat   A    5
sun   A    0
mon   B   12
tue   B    0
wed   B    0
thu   B    3
fri   B   16
sat   B    9
sun   B   23
mon   C    0
tue   C    5
wed   C   21
thu   C    0
fri   C    0
sat   C   17
sun   C    0

ie: The empty values are filled with zeroes, I can create the format I
want by doing a multiple self-join.  However, to make this work, I
need an efficient way to insert all those missing zeroes.  Any ideas?


Thanks

Brent

if possible, please cc a copy of your reply to brent@ugcs.caltech.edu





--

--
Brent Eubanks					    brent@ugcs.caltech.edu
Technical Details
Message-ID: <5jn3g3$2nd@gap.cco.caltech.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11355a,5ce765e83b646b2f,start
X-Google-Attributes: gid11355a,public
X-Google-Thread: 104de1,5ce765e83b646b2f,start
X-Google-Attributes: gid104de1,public
From: brent@ugcs.caltech.edu (Brent Eubanks)
Subject: Need help transforming results set format
Date: 1997/04/24
Message-ID: <5jn3g3$2nd@gap.cco.caltech.edu>
X-Deja-AN: 237066936
Organization: California Institute of Technology, Pasadena
Newsgroups: comp.databases.ms-sqlserver,bit.listserv.sqlinfo