Re: Odd pivot table type query

From: Shawn (shawngerty_at_hotmail.com)
Date: 11/23/04


Date: Mon, 22 Nov 2004 17:09:50 -0800

Thanks for the response Vishal. Unfortunatly this
solution isn't going to work for me since I dealing with a
very large number of records the performace of populating
a new table is going to be too great.

I'm adding a "download" feature for the data so this would
result is a large number of records being retuned and
written to file.

What would be great is is I could use somethine like a
GROUP BY and SUM where the SUM would append strings
together.

SELECT year, APPEND(Quarter)
FROM mytable
GROUP BY year

>-----Original Message-----
>For documented method, you will have to make use of
procedural code to
>achieve this. See following example. OR you will have to
use some 3rd party
>tool to do it(www.rac4sql.com).
>
>Eg:
>-- sample table
>-- if object_id('tab') is not null
>-- drop table tab
>
>create table tab(ID int,
>SEQ_NUM int ,
>ROUTE varchar(50))
>go
>-- sample data
>insert into tab values
(1 ,1 ,'AA')
>insert into tab values
(1 ,2 ,'BB')
>insert into tab values
(1 ,3 ,'CC')
>insert into tab values
(2 ,1 ,'AA')
>insert into tab values
(3 ,1 ,'VV')
>insert into tab values
(3 ,2 ,'XX')
>go
>-- t-sql code for generating report
>if object_id('tempdb..#tmp') is not null
>drop table #tmp
>
>create table #tmp(id int, tmpval varchar(50))
>go
>declare @id int
>declare @seq_num int
>declare @route varchar(50), @f_route varchar(50)
>
>select @id=0, @seq_num=0, @route='', @f_route=''
>
>while @id is not null
>begin
> select @id=min(id) from tab where id > @id
> while @seq_num is not null
> begin
> select @seq_num=min(seq_num), @route=min(route)from
tab where id = @id
> and seq_num > @seq_num
> If @seq_num is null and @id is not null
> insert into #tmp values(@id, @f_route)
> select @f_route = @f_route + case @f_route when ''
then '' else ','
>end + @route
> end
> select @seq_num=0, @f_route=''
>end
>select * from #tmp
>truncate table #tmp
>
>--
>
>Vishal Parkar
>vgparkar@yahoo.co.in | vgparkar@hotmail.com
>
>
>.
>



Relevant Pages

  • A source file de-tabifier for you
    ... *transform* one tab setting to another; thus, you can write your code with ... void do_line; ... int reset_on_com = FALSE; ... char **argv; ...
    (alt.comp.lang.learn.c-cpp)
  • Re: newbie question
    ... int main{ ... The problem is that some news readers clients (or is it some news ... server, I don't know) strip the TAB and consequently, your code appears ...
    (comp.lang.c)
  • Re: exercise 1-20 K&R
    ... of blanks to space to the next tab stop. ... int counter, c; ... character count for the current line, ... Tab stops are at the same character number (modulo TABSIZE) throughout ...
    (comp.lang.c)
  • Re: I dont quite understand this exercise...
    ... >ask the user/get and set a variable, say n, and replace all tabs with n ... A text file containing some tab characters. ... if N is 4 and the original file is: ... int jj = 0; ...
    (comp.lang.c)
  • [patch 1/14] s3c2412/s3c2413 support
    ... +s3c_lookup_cpu(unsigned long idcode,int alt) ... struct cpu_table *tab; ... int count; ...
    (Linux-Kernel)