[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Convert style values

Posted on 2004-11-01
3
Medium Priority
?
1,530 Views
Last Modified: 2008-02-07
I am trying to convert from "July 30, 2004" to "JULY 30, 2004".  I have the code for the short date i.e. JUL 30, 2004 but I need the month spelled out.  This date field is being built in a work table inside a stored procedure then it is passed into Crystal Reports v8.0.  I would like to do all the date formating inside the stored procedure so I don't run into Crystal issues down the road when I do my upgrade project.

Here is what I am doing so far:
UPPER(convert(varchar,convert(datetime,#rptrows.print_date),107))

This Outputs: JUL 30, 2004 I want JULY 30, 2004

Is there an undocumented style number that will do this or do I need to perform some crazy formating or write a case statement?

Any help would be appreicated.

msas94-
0
Comment
Question by:msas1994
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:sigmacon
ID: 12465531
Maybe this?

UPPER(DATENAME(month, #rptrows.print_date)) + ' ' + DAY(#rptrows.print_date) + ', ' + YEAR(#rptrows.print_date)
0
 
LVL 3

Expert Comment

by:sanjaykp
ID: 12465847
Your field seems to be in string format since you're converting it to datetime and then back to a varchar. You're better off leaving it like a date field and passing it on to Crystal Reports as a datetime value (don't use smalldatetime, problems), since Crystal has excellent customizable field displays (Format Field...). Another advantage being, the field can be used natively as a datetime by any application.  
0
 
LVL 8

Accepted Solution

by:
MartinCMS earned 1000 total points
ID: 12465853
try this...

UPPER(DATENAME(month, getdate())) + ' ' + right('00'+Convert(varchar(2),DAY(getdate())),2) + ', ' + Convert(varchar(4),YEAR(getdate()))

right('00'  - function add zero infront for day between 1-9
Convert(varchar(2) - function will convert day digit into varchar to avoid miss match
Convert(varchar(4) - function will convert year digits into varchar to avoid miss match

Select UPPER(DATENAME(month, getdate())) + ' ' + right('00'+Convert(varchar(2),DAY(getdate())),2) + ', ' + Convert(varchar(4),YEAR(getdate()))

result: NOVEMBER 21, 2004
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

656 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