CAST AND CONVERT T-SQL

Trying to take a two step process down to one step.  I'm if got a date stored as 20110119(YYYYMMDD), this date represents  Jan 19, 2011.  

Currently, I'm using a data step approach using a WITH statement.

WITH T1 AS
(
Select  CAST(FromDate AS DATE) AS FmDt
From MyTable
/* this takes it from 20110119 to 2011-01-19 */
)

Select CONVERT(NVARCHAR(110), T1.PgmFmDt, 110) AS PgmFmDt
/* this takes it from 2011-01-19 to 01-19-2011 */

What I really want to do is go direct from 20110119 to 01/19/2011, notice I'm also want to replace the - with /.    

Your thoughts?
P19_3141Asked:
Who is Participating?
 
Paul JacksonSoftware EngineerCommented:
Pretty sure this is all you need to do

Select  CONVERT(nvarchar(30),CAST(FromDate As DateTime), 101) AS FmDt
From MyTable
0
 
P19_3141Author Commented:
After a day of playing with it on my own.......The answer magically appears on EE in under 5 mins.  

That did the trick.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.