Reputation: 1581
I am trying to truncate a date entry that includes the time data and set change its variable name in a single select statement.
SELECT Database.Schema.Variable AS newVariableName AS date
Here the variable outputs as 2017-12-28T09:17:15.250Z
, but I would like it to output 2017-12-28
.
I'm currently getting a Incorrect syntax near the keyword 'AS'
error...
Upvotes: 0
Views: 282
Reputation: 1289
Try:
SELECT FORMAT(Database.Schema.Variable, 'yyyy/MM/dd', 'en-us') AS newVariableName
The page says it applies to Transact SQL but I ran a quick test on a datetime field from my db and was good to go: https://learn.microsoft.com/en-us/sql/t-sql/functions/format-transact-sql
For SQL-Server 2008:
SELECT CONVERT(VARCHAR(10), Database.Schema.Variable, 111) AS newVariableName
Was found here: http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx
Upvotes: 1
Reputation: 13393
Try this.
SELECT cast(Database.Schema.Variable AS date) as newVariableName
Upvotes: 1