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 |
|
shaw
Starting Member
15 Posts |
Posted - 2007-05-03 : 14:05:06
|
| hi there,i have a table with 1 column going like this:7/1/2001 7/2/2001 7/3/2001 7/4/2001 7/5/2001 7/6/2001i have another table with 1 column going like this:07/01/2001 0107/01/2001 0207/01/2001 0307/01/2001 0407/01/2001 0507/01/2001 0607/01/2001 0707/01/2001 0807/01/2001 0907/01/2001 1007/01/2001 1107/01/2001 1207/01/2001 1307/01/2001 1407/01/2001 1507/01/2001 1607/01/2001 1707/01/2001 1807/01/2001 1907/01/2001 2007/01/2001 2107/01/2001 2207/01/2001 2307/01/2001 2407/02/2001 0107/02/2001 0207/02/2001 0307/02/2001 0407/02/2001 05In the second table, I want to create a second column. Into it, I want to put the 7/1/2001 value for all values that starts with 7/1/2001 in the second table .This is basically putting the daily data for all hours for that day.You have any idea for the script?Thanks |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-03 : 14:09:22
|
quote: Originally posted by shaw.... I want to put the 7/1/2001 value for all values that starts with 7/1/2001 in the second table ...
Can you repharse that please?Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
shaw
Starting Member
15 Posts |
Posted - 2007-05-03 : 14:18:58
|
| sure,my main table is hourly.so it goes as the following (this is one column)07/01/2001 0107/01/2001 0207/01/2001 0307/01/2001 0407/01/2001 05my daily column is like this one:7/1/20017/2/20017/3/20017/4/2001Now I want to take the dates in my second table and put them into my hourly (first) table.For ex:Take '7/1/2001' in my second table and put it 24 times in my first table as '07/01/2001'. So that at the end, I will have the following:07/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/01/200107/02/200107/02/200107/01/2002....24 times for each day.Is it more clear? |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-03 : 14:42:36
|
Create a table variable with all the 24 rows '01' through '24', then do an insert with a CROSS JOIN.Declare @hourly table (col1 datetime, col2 varchar(5))Declare @daily table (col1 datetime)Declare @hours table (col1 varchar(5))insert into @hours values ('01')insert into @hours values ('02')insert into @hours values ('03')insert into @hours values ('04')insert into @hours values ('05')insert into @daily values ('7/1/2001')insert into @daily values ('7/2/2001')insert into @daily values ('7/3/2001')insert into @daily values ('7/4/2001')insert into @hourlyselect * from @dailycross join @hoursselect * from @hourly order by col1,col2Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
shaw
Starting Member
15 Posts |
Posted - 2007-05-03 : 16:54:51
|
| thanks for this Dinakar.worked. |
 |
|
|
|
|
|