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)
 Export tables

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)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-03 : 04:11:16
you mean month names?
Go to Top of Page

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.
Go to Top of Page

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?
Go to Top of Page

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.
Go to Top of Page

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

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

whitmoj
Yak Posting Veteran

68 Posts

Posted - 2008-11-03 : 04:58:08
Many thanks Madhivanan the code worked a dream!!!!!!!!
Go to Top of Page

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

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -