November 24, 2008 at 8:29 pm
Hi I have a table A
----------------------------------------
Date 1M 2m 3m 4m
----------------------------------------
20080523 1.2 2.1 3.7 1.7
20080524 1.3 2.6 3.0 1.2
20080525 1.2 2.3 3.2 1.5
20080526 1.7 2.8 3.2 1.3
My requirement is to get a temp table like
----------------------------------------------------------
Tenor 20080523 20080524 20080525 20080526
-----------------------------------------------------------
1m 1.2 1.3 1.2 1.7
2m 2.1 2.6 2.3 2.8
3m 3.7 3.0 3.2 3.2
4m 1.7 1.2 1.5 1.3
Could u please help us as it is very urgent.
Thanx
Kiran
November 24, 2008 at 9:04 pm
I need a dynamic query that executes any number of rows.not for only four dates.
Kiran
November 24, 2008 at 9:40 pm
Kiran Kumar MP (11/24/2008)
Hi I have a table A----------------------------------------
Date 1M 2m 3m 4m
----------------------------------------
20080523 1.2 2.1 3.7 1.7
20080524 1.3 2.6 3.0 1.2
20080525 1.2 2.3 3.2 1.5
20080526 1.7 2.8 3.2 1.3
My requirement is to get a temp table like
----------------------------------------------------------
Tenor 20080523 20080524 20080525 20080526
-----------------------------------------------------------
1m 1.2 1.3 1.2 1.7
2m 2.1 2.6 2.3 2.8
3m 3.7 3.0 3.2 3.2
4m 1.7 1.2 1.5 1.3
Could u please help us as it is very urgent.
Thanx
Kiran
how many rows and what index of column(s) you want to convert in the columns. Im asking this as sql does not proviedes unlimited number of columns.
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
November 24, 2008 at 10:09 pm
the table is having lakhs of rows.if i select a date range from 1-10
there should be fixed (Tenor) column for alll date ranges and other columns are dates basing on the range.
ie
if date range is (1-10)
Tenor 1 2 3 4 5 6 7 8 9 10
if date range is (1-5)
Tenor 1 2 3 4 5
like that.
Kiran
November 24, 2008 at 10:29 pm
Kiran Kumar MP (11/24/2008)
the table is having lakhs of rows.if i select a date range from 1-10there should be fixed (Tenor) column for alll date ranges and other columns are dates basing on the range.
ie
if date range is (1-10)
Tenor 1 2 3 4 5 6 7 8 9 10
if date range is (1-5)
Tenor 1 2 3 4 5
like that.
Kiran
give me 20 minutes . im near to completion
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
November 24, 2008 at 10:38 pm
krayknot (11/24/2008)
Kiran Kumar MP (11/24/2008)
the table is having lakhs of rows.if i select a date range from 1-10there should be fixed (Tenor) column for alll date ranges and other columns are dates basing on the range.
ie
if date range is (1-10)
Tenor 1 2 3 4 5 6 7 8 9 10
if date range is (1-5)
Tenor 1 2 3 4 5
like that.
Kiran
give me 20 minutes . im near to completion
Is this helpful
declare @colname varchar(100)
declare @rowcolname varchar(1000)
set @rowcolname = ''
declare col CURSOR FOR
select id from actionstate
open col
fetch next from col into @colname
while @@fetch_status = 0
begin
set @rowcolname = @rowcolname + '[' + @colname + '] int,'
fetch next from col into @colname
end
close col
deallocate col
print('Create TAble tablename('+ @rowcolname + ')')
exec('Create TAble tablename('+ @rowcolname + ')')
select * from tablename
drop tablename
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
November 24, 2008 at 10:49 pm
Hi shitij
Could you please give me the structure of actionstate?
kiran
November 24, 2008 at 10:56 pm
Kiran Kumar MP (11/24/2008)
Hi shitijCould you please give me the structure of actionstate?
kiran
it has two columns
ID(int) IDDesc(varchar)
1 abcd
2 xyz
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
November 24, 2008 at 11:10 pm
Thanx yaar
November 24, 2008 at 11:13 pm
Kiran Kumar MP (11/24/2008)
Thanx yaar
will it work??
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
November 24, 2008 at 11:14 pm
Kiran Kumar MP (11/24/2008)
Hi I have a table A----------------------------------------
Date 1M 2m 3m 4m
----------------------------------------
20080523 1.2 2.1 3.7 1.7
20080524 1.3 2.6 3.0 1.2
20080525 1.2 2.3 3.2 1.5
20080526 1.7 2.8 3.2 1.3
My requirement is to get a temp table like
----------------------------------------------------------
Tenor 20080523 20080524 20080525 20080526
-----------------------------------------------------------
1m 1.2 1.3 1.2 1.7
2m 2.1 2.6 2.3 2.8
3m 3.7 3.0 3.2 3.2
4m 1.7 1.2 1.5 1.3
Could u please help us as it is very urgent.
Thanx
Kiran
you can use PIVOT option, if your database is SQL 2005 and above version.
for more info see SQL BOL.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply