Author |
Topic |
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-12-10 : 03:18:46
|
Can i still get the sum of a field even if the data type is of type varchar?thanks!Funnyfrog |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-10 : 03:22:14
|
convert to integer / numeric first. Make sure that all your data is numeric value KH[spoiler]Time is always against us[/spoiler] |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-12-10 : 03:36:04
|
what is wrong with my conversion below?select (convert(varchar(8),visits055,112)as INT)as t from bills where code = '01'Funnyfrog |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-12-10 : 03:36:53
|
what is wrong with my conversion below?select (convert(varchar(8),visits055,112)as INT)as t from bills where code = '01'i want to convert it because i wanted to get the sum of it..Funnyfrog |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-10 : 03:37:56
|
what is the data type of visits055 ? why are you converting to varchar then to integer ? KH[spoiler]Time is always against us[/spoiler] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-10 : 03:39:05
|
you are mixing convert() syntax with cast() syntax. convert(int, convert(varchar(8), visits055, 112))visits055 is datetime ? And why are you summing up the date YYYYMMDD ? It does not make sense to sum a date like 20071201 + 20071202 + 20071203 KH[spoiler]Time is always against us[/spoiler] |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-12-10 : 03:39:22
|
its datatype is varchar..i want to cconvert it because i want to get the sum of visits055.Funnyfrog |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2007-12-10 : 03:42:56
|
this is the script that you posted: convert(int, convert(varchar(8), visits055, 112))if i do it like this sum(convert(int, convert(varchar(8), visits055, 112))) am i on the right track?thanks!Funnyfrog |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-10 : 03:48:11
|
quote: Originally posted by shemayb this is the script that you posted: convert(int, convert(varchar(8), visits055, 112))if i do it like this sum(convert(int, convert(varchar(8), visits055, 112))) am i on the right track?thanks!Funnyfrog
Can you post some sample data with expected result?How about having a proper int or decimal datatype?MadhivananFailing to plan is Planning to fail |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-10 : 03:48:45
|
quote: Originally posted by shemayb its datatype is varchar..i want to cconvert it because i want to get the sum of visits055.Funnyfrog
since it is in varchar()just use convert(int, visits055) KH[spoiler]Time is always against us[/spoiler] |
|
|
|