Author |
Topic |
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2012-08-18 : 11:13:49
|
Hi,I have a date column with varchar(50) as datatype with values like 01/08/201202/08/201203/08/2012When I try to convert this in '20120801' format using the code below, i get the error arithmetic overflow error converting expression to data type datetimeselect convert(varchar(8),cast(date as datetime),112) as date, field1 from mytable |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-18 : 11:19:17
|
no need of inner castselect convert(varchar(8),[date],112) as date, field1 from mytable ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-18 : 11:22:06
|
b/w one question is the original values in dd/mm/yyyy or mm/dd/yyyy format?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2012-08-18 : 11:22:55
|
[code]select convert(varchar(8),[date],112) as date, field1 from mytable[/code]The above code displays date as '01/08/20''02/08/20''03/08/20'But I want output as'20120801''20120802''20120803'@visakhI just read your second post..original values are 'dd/mm/yyyy' |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-18 : 11:28:07
|
[code]select convert(varchar(8),convert(datetime,[date],103),112) as [date], field1 from mytable[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2012-08-18 : 13:21:11
|
As usual, many thanks visakh16. It works now. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-18 : 15:16:47
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-09-03 : 10:09:46
|
1 Always use proper DATETIME datatype to store dates2 Formation matters only when you want to show them somewhereMadhivananFailing to plan is Planning to fail |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|