Solved

CAST AND CONVERT T-SQL

Posted on 2012-03-29
2
323 Views
Last Modified: 2012-03-29
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?
0
Comment
Question by:P19_3141
2 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 37782698
Pretty sure this is all you need to do

Select  CONVERT(nvarchar(30),CAST(FromDate As DateTime), 101) AS FmDt
From MyTable
0
 

Author Closing Comment

by:P19_3141
ID: 37782840
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

759 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

20 Experts available now in Live!

Get 1:1 Help Now