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.
| Author |
Topic |
|
sushil.arthi
Starting Member
1 Post |
Posted - 2005-03-01 : 01:13:29
|
| Hi,I am not able to add a dynamic column to a dynamic table in SQL Server. This scenario came when i need to retrieve a set of employees who are working in an organization with the specific effort they have put per each day with which, i will get the list of employees with the day-wise effort of each employee. I tried in this way...Declare @dtFromDate as DatetimeDeclare @dtToDate as DatetimeSet @dtFromDate = '2/2/2005'Set @dtToDate = '3/3/2005'Declare @date_Table Table (DDate Varchar(20))while @dtFromDate <= @dtToDateBegin Insert into @date_Table values (@dtFromDate) Set @dtFromDate = DateAdd(Day,1,@dtFromDate)EndDeclare @Result_Table Table (EmpName Varchar(60))Declare @col_Date as Varchar(20)Declare @Date_Cursor Cursor For Select DDate From @date_TableOpen @Date_CursorFetch Next From @Date_Cursor into @col_Datewhile @@FETCH_STATUS = 0Begin Alter table @Result_Table Add @col_Date Varchar(20) Null Fetch Next From @Date_Cursor into @col_DateEndClose @Date_CursorDeallocate @Date_CursorPlz help me out...Thanks in advance,Regards,Sushil |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-03-01 : 07:12:55
|
| It looks like you're trying to do a cross tab, try this instead:http://www.sqlteam.com/item.asp?ItemID=2955 |
 |
|
|
|
|
|