Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CAST AND CONVERT T-SQL

Posted on 2012-03-29
2
Medium Priority
?
342 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 2000 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

Technology Partners: 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

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
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database 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.

662 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