Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-19 : 08:22:55
|
DECLARE @table TABLE(value NVARCHAR(30), fieldName Varchar(10))INSERT INTO @table VALUES('Jan 29 2013 12:00AM', 'pur_date'), ('afvajfab', 'sft_name')SELECT CASE WHEN fieldName = 'pur_date' THEN need mm/dd/yyyyELSE value ENDFROM @tablei want output in the format of mm/dd/yyyyNote: while unpivoting values i have changed datetime column to Nvarchar ( it must need for me)..Now i want above format for display..How to do that? please help me--Chandu |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-19 : 08:44:14
|
[code]DECLARE @table TABLE(value NVARCHAR(30), fieldName Varchar(10))INSERT INTO @table VALUES('Jan 29 2013 12:00AM', 'pur_date'), ('afvajfab', 'sft_name')SELECT CASE WHEN fieldName = 'pur_date' THEN CONVERT(VARCHAR(32),CAST([value] AS DATETIME),101)ELSE value ENDFROM @table[/code] |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-02-19 : 08:44:41
|
DECLARE @table TABLE(value NVARCHAR(30), fieldName Varchar(10))INSERT INTO @table VALUES('Jan 29 2013 12:00AM', 'pur_date'), ('afvajfab', 'sft_name')SELECT CASE WHEN fieldName = 'pur_date' THEN convert(varchar(10),convert(datetime,value,100),101)ELSE value ENDFROM @table Too old to Rock'n'Roll too young to die. |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-19 : 09:28:14
|
Thank you--Chandu |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2013-02-19 : 09:29:51
|
obligatory "format in front end" comment here... How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-02-19 : 09:50:46
|
quote: Originally posted by DonAtWork obligatory "format in front end" comment here... How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
it was about time cheers Too old to Rock'n'Roll too young to die. |
|
|
|
|
|
|
|