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 2008 Forums
 Transact-SQL (2008)
 Help Retreiving Last Months Records

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2011-09-20 : 14:01:18
I am trying to retreive all of last months records from a table.

I have a column called "rDate" which is a char(6). Values in this column look like "01SP11", "02SP11", "03SP11", etc....

pseudo code:

select * from myTable
where month(rDate) = getDate() - one Month

Any suggestions?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-20 : 22:08:09
what kind of date format is this? so how will you represent January,February etc?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2011-09-21 : 08:44:02
Guess I am looking to convert JA = 01, FB = 02, MR = 03, etc...
And then compare rDate = presentDate - one month.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 08:46:18
then best way is to have mapping table for that otherwise you will end up putting lots of case when constructs

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2011-09-21 : 11:50:59
Mapped table worked like a champ!

Thanks for the suggestion.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-21 : 11:52:46
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -