Solved

CAST AND CONVERT T-SQL

Posted on 2012-03-29
2
335 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
[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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

734 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