Geeks Talk

Prepare for your Next Interview




To get previous month names

This is a discussion on To get previous month names within the SQL Server forums, part of the Databases category; How can i get last there previous month names by useing system date...


Go Back   Geeks Talk > Databases > SQL Server

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-01-2008
Junior Member
 
Join Date: Mar 2008
Location: hyderabad
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
boreddy is on a distinguished road
To get previous month names

How can i get last there previous month names by useing system date
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-01-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: To get previous month names

Select to_char(add_months(sysdate,-rownum),'month') prev_months from user_tables where rownum<=3;
Reply With Quote
  #3 (permalink)  
Old 04-01-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,432
Thanks: 8
Thanked 126 Times in 113 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: To get previous month names

Quote:
Originally Posted by krishnaindia2007 View Post
Select to_char(add_months(sysdate,-rownum),'month') prev_months from user_tables where rownum<=3;
Will that work in SQL server ?
Reply With Quote
  #4 (permalink)  
Old 04-02-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: To get previous month names

Quote:
Originally Posted by debasisdas View Post
Will that work in SQL server ?
Sorry. I answered the question without observing forum.
Reply With Quote
  #5 (permalink)  
Old 04-03-2008
Junior Member
 
Join Date: Mar 2008
Location: hyderabad
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
boreddy is on a distinguished road
Re: To get previous month names

I got the answer for question


select datename(month, dateadd("month",-1,getdate())), datename(month, dateadd("month",-2,getdate())),
datename(month, dateadd("month",-3,getdate()))
Reply With Quote
  #6 (permalink)  
Old 09-18-2008
Junior Member
 
Join Date: Apr 2008
Location: Hyderabad
Posts: 28
Thanks: 1
Thanked 4 Times in 2 Posts
nageshkota is on a distinguished road
Re: To get previous month names

Sorry boreddy u cant use month is quotes.

Use
select datename(month, dateadd(month,-1,getdate())), datename(month,
dateadd(month,-2,getdate())),datename(month, dateadd(month,-3,getdate()))
Reply With Quote
Reply

  Geeks Talk > Databases > SQL Server


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
To read the previous record from the last farhana MainFrame 0 12-13-2007 02:51 AM
Find previous executed SQL pande.dhiraj SQL 3 11-20-2007 04:16 AM
I want to get the previous row from a table divya_rad SQL 7 07-25-2007 03:56 AM
Latest and previous versions of LR, Winrunner and QC karthik.dr WinRunner 0 06-06-2007 12:51 AM
find current and previous profession... psuresh1982 Brainteasers 21 01-08-2007 05:55 AM


All times are GMT -4. The time now is 12:21 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved