Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'CONVERT'.

Chris Slinko 1 Reputation point
2020-08-20T19:57:17.57+00:00

I have this table that I'm trying to convert "2004-06-08 00:00:00.0000000" Datetime to just Date mm/dd/yyyy. Each row has a unique date. This is the code that I used below. This "Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'CONVERT'."

USE taxpayer
SELECT SALESDATE FROM VISION_SALEHIST4,
CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY]

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,770 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Tom Phillips 17,731 Reputation points
    2020-08-20T20:12:28.257+00:00

    You have your CONVERT after the FROM clause.

    USE taxpayer  
    SELECT SALESDATE   
    ,CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY]  
    FROM VISION_SALEHIST4  
      
    

    Please see:
    https://learn.microsoft.com/en-us/sql/t-sql/queries/select-transact-sql?view=sql-server-ver15

    1 person found this answer helpful.
    0 comments No comments

  2. CathyJi-MSFT 22,201 Reputation points Microsoft Vendor
    2020-08-21T02:21:42.043+00:00

    Hi ChrisSlinko,

    Please try below T-SQL;

    use taxpayer  
    select convert(varchar(10), cast(SALESDATE as date), 101) from VISION_SALEHIST4  
    

    19334-annotation-2020-08-21-102103.jpg
    If the response helped, do "Accept Answer" and upvote it.

    Best regards,
    Cathy

    1 person found this answer helpful.

  3. Guoxiong 8,206 Reputation points
    2020-08-20T20:36:37.663+00:00

    If the data type of the column SALESDATE is datetime or datetime2, you can also use the FORMAT function to convert the date:

    USE taxpayer  
    SELECT FORMAT(SALESDATE, 'MM/dd/yyyy', 'en-US')  AS [MM/DD/YYYY]  
    FROM VISION_SALEHIST4;  
    

    See FORMAT for the details.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.