| Author |
Topic |
|
arunsqladmin
Yak Posting Veteran
74 Posts |
Posted - 2008-01-29 : 00:09:59
|
| i am getting error while convering datetime datatype using convert(x,101)functionArithmetic overflow error converting expression to data type datetimeplease help me |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-29 : 00:15:46
|
what is the format of your datetime string ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
arunsqladmin
Yak Posting Veteran
74 Posts |
Posted - 2008-01-29 : 00:19:12
|
| select convert(varchar(20),convert(datetime,validity),107) as validity, fileno, name, country,program, supervisor, phoneno, category from apprentices where category='Apprentice'and convert(datetime, validity) > getdate() |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-29 : 00:27:23
|
tryconvert(datetime, validity, 107) > getdate() KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
arunsqladmin
Yak Posting Veteran
74 Posts |
Posted - 2008-01-29 : 00:33:53
|
| i tried even that , it is not working |
 |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-01-29 : 00:36:23
|
| Can you provide sample data on which you are running your query? Perhaps that may help in solving your problem.Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-29 : 00:40:49
|
quote: Originally posted by khtan what is the format of your datetime string ? KH[spoiler]Time is always against us[/spoiler]
check your data in the validity field. There are some rows that of different format KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
arunsqladmin
Yak Posting Veteran
74 Posts |
Posted - 2008-01-29 : 01:03:40
|
| 1)SELECT CONVERT(varchar(20), CONVERT(datetime, Validity), 101) AS validity, Fileno, Name, Country, Program, Supervisor, Phoneno, categoryFROM ApprenticesWHERE (category = 'Research Fellow') AND (CONVERT(datetime, Validity) > GETDATE())2)SELECT CONVERT(varchar(20), CONVERT(datetime, Validity), 101) AS validity, Fileno, Name, Country, Program, Supervisor, Phoneno, categoryFROM ApprenticesWHERE (category = 'apprentice') AND (CONVERT(datetime, Validity) > GETDATE())first one works but the second one does not work.. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-29 : 01:15:59
|
it means you have datetime in string for category = 'apprentice' that is not in proper 101 formattryselect Validity, Fileno, NameFROM ApprenticesWHERE category = 'apprentice'and isdate(Validity) = 0to identify the rows with invalid date format in string. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
arunsqladmin
Yak Posting Veteran
74 Posts |
Posted - 2008-01-29 : 01:34:50
|
| select Validity, Fileno, NameFROM ApprenticesWHERE category = 'apprentice'and isdate(Validity) = 0there is one record which shows invalid format ,,, what should i do next |
 |
|
|
arunsqladmin
Yak Posting Veteran
74 Posts |
Posted - 2008-01-29 : 01:46:46
|
| i have solved the issue ,, u r a genius Mr.KH.. hats off to u |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|