Author |
Topic |
whitmoj
Yak Posting Veteran
68 Posts |
Posted - 2008-11-03 : 03:57:20
|
Hi I am having a bit of a brain freeze I am trying to populate a tbl with two months worth of data ( current month & previous) I have the code for current month WHERE DATEADD(mm,DATEDIFF(mm,0,[Date]),0)=DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) and I know if I put -1 before the comma and 0 it will give me last month is there any code I can pass throught to give me the months. |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-03 : 04:06:21
|
WHERE [Date]>=DATEADD(month,DATEDIFF(month,0,GETDATE())-1,0)MadhivananFailing to plan is Planning to fail |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 04:11:16
|
you mean month names? |
 |
|
whitmoj
Yak Posting Veteran
68 Posts |
Posted - 2008-11-03 : 04:16:11
|
No I want to update the tbl with two months worth of data EG last month was 31 days so when I run the insert statement today my table will be populated with 33 rows. I am just waiting for SP to finish and I will try madhivanan suggestion and see if this works. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 04:22:39
|
33 rows for 31 days? what are extra two rows for? month totals? |
 |
|
whitmoj
Yak Posting Veteran
68 Posts |
Posted - 2008-11-03 : 04:27:13
|
No this month. So by the time I get to the end of this month and my SP runs on the 1st Dec I will have 61 rows (October & November) data and when it runs on the 2nd Dec I will have (November's 30 days and 1 day for Dec). Get what I want to do now. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-03 : 04:44:50
|
quote: Originally posted by whitmoj No this month. So by the time I get to the end of this month and my SP runs on the 1st Dec I will have 61 rows (October & November) data and when it runs on the 2nd Dec I will have (November's 30 days and 1 day for Dec). Get what I want to do now.
The code I posted would do that MadhivananFailing to plan is Planning to fail |
 |
|
whitmoj
Yak Posting Veteran
68 Posts |
Posted - 2008-11-03 : 04:58:08
|
Many thanks Madhivanan the code worked a dream!!!!!!!! |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-03 : 05:02:30
|
quote: Originally posted by whitmoj Many thanks Madhivanan the code worked a dream!!!!!!!!
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|