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 |
hspatil31
Posting Yak Master
182 Posts |
Posted - 2013-05-25 : 08:25:40
|
Dear All,I am trying following query. I have field nvarchar in ABC table which contains the date(Format: 12/12/2013).I want to convert this to DATE. I am getting following error :Error:"Conversion failed when converting date and/or time from character string."Can anyone please help me how to convert to DATE ?Query:SELECT DISTINCT PIDTBL.Id, CONVERT(DATE,SAO.Name)FROM [ABC] PIDTBL INNER JOIN [XYZ] PSAM ON PIDTBL.Id = PSAM.ProductId INNER JOIN [PQR] SAO ON PSAM.SpecificationAttributeOptionId = SAO.Id WHERE SAO.SpecificationAttributeId = 12Thanks and Regard'sHarish Patil |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-25 : 08:30:11
|
Are you using dd/mm/yyyy format, or mm/dd/yyyy format? Can't tell from the 12/12/2013 example that you are using.If you are using dd/mm/yyyy format, use CONVERT(DATE,SAO.Name, 103) and if you are using mm/dd/yyyy format, use CONVERT(DATE,SAO.Name, 101)The 103 and 101 are styles - see here: http://msdn.microsoft.com/en-us/library/ms187928.aspxYou can avoid this type of problem if you specify your date literals in the unambiguous format for YYYYMMDD, for example '20130127'. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|