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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 t-sql 2012 give column name and format date field

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2014-09-24 : 11:53:49
In t-sql 2012 I have a select statement that looks like the following:

Select CONVERT(smalldatetime,CS.value,101) AS [MM/DD/YYY].

My problem is that I want to call this field [Beginning Date]. I need to also format the date in mm/dd/yyyy format.

I can not get the field formatted in mm/dd/yyyy format and call the field [Beginning Date].

Thus can you show me the t-sql to solve my problem?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-09-24 : 13:41:38
Your alias isn't changing the format anyhow. The issue is with the data type. You need to use char/varchar for this:

Select CONVERT(varchar(10),CS.value,101) AS [Beginning Date]

But this really shouldn't be done in T-SQL. It is a presentation layer issue and should be done in the application. Return raw data from SQL. Format data in the application.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2014-09-24 : 14:45:37
thanks!
Go to Top of Page
   

- Advertisement -