views:

86

answers:

1

Hi guys,

I want to convert a DATETIME field (DateOfBirth)... When I execute the following query it says invalid syntax near convert

SELECT e.Emp_Id,e.Emp_Name,e.Address,e.Department,
(convert(varchar, e.Date_Of_Birth, 103) as Date_Of_Birth) from Employee as e 

But when I execute the below query it gives result but my dateofbirth column name is (No Column Name)

SELECT e.Emp_Id,e.Emp_Name,e.Address,e.Department,
(convert(varchar, e.Date_Of_Birth, 103)) from Employee as e 

Why cant I give an alias name as column name to a convert function?

A: 

Drop the extra comma:

SELECT e.Emp_Id,e.Emp_Name,e.Address,e.Department, 
convert(varchar, e.Date_Of_Birth, 103) as Date_Of_Birth
FROM Employee as e  
Mitch Wheat
@Mitch sorry that was my editing mistake.. see my edited question
Pandiya Chendur
Does the query I posted work (note removed extra parentheses)?
Mitch Wheat
@Mitch it worked...
Pandiya Chendur