Solved

Need to convert smalldatetime to: eg; Jan'06

Posted on 2006-11-10
5
196 Views
Last Modified: 2008-02-01
Howdy
I need a quick SELECT statement to convert a smalldatetime field to this format: Jan'06
Eg; 01-23-2006 00:00:00 to Jan'06

thanks a lot!!!
Fergal
0
Comment
Question by:fjkilken
  • 3
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 17914860
select convert(varchar(3),yourDateCol,107) + '''' + substring(convert(varchar(4),yourDateCol,121),2,2)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 17914866
for example, using the getDate() function:

select convert(varchar(3),getdate(),107) + '''' + substring(convert(varchar(4),getdate(),121),2,2)
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 125 total points
ID: 17914885
OOPS!  but change the last parameter from   2,2  to  3,2

select convert(varchar(3),yourDateCol,107) + '''' + substring(convert(varchar(4),yourDateCol,121),3,2)
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17914910
SELECT CONVERT(varchar(3),getdate())+''''+RIGHT(YEAR(getDate()),2)
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17914912
I was just about to correct you ;)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now