Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamic Table

Author  Topic 

zubairmasoodi
Starting Member

35 Posts

Posted - 2007-04-20 : 05:08:10
Hi EveryBody
I need to dynamically create a table whose no of columns would be dynamic.
The Actual problem is like this
Base on Two dates Startdate and EndDate
The no of columns in the table should be equal to the no of days betwee the start and end dates
Suppose the StartDate= 4/1/2007 and EndDate=4/30/2007
I need a to create a Table which will contain 30 columns corresponding to each date between two input dates

Any help is greatly appreciated
Thanks
Zub

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-20 : 05:34:34
why do you need to do this ? What is the objective ?


KH

Go to Top of Page

zubairmasoodi
Starting Member

35 Posts

Posted - 2007-04-20 : 06:03:04
Thanks for Reverting
Basically i have to generate a Report which shall contain the no of sales for each day the company has generated in the given period of time. i need to use a temporary table in my procedure of the
already mentioned format

Thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-21 : 00:04:14
Can't you do this in your reporting tool rather than in SQL ?

You can create a table with date as one of the column and transpose it. Search the forum for CROSS TAB or PIVOT table.


create table #temp
(
[date] datetime,
value int
)


If you really want to create at table with the number of columns = number of days, you can still do it in t-sql but you will have to use Dynamic SQL. see http://www.sommarskog.se/dynamic_sql.html


KH

Go to Top of Page
   

- Advertisement -