Author |
Topic |
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2008-07-10 : 05:13:06
|
Hello Friends,i have a string field of total length of 6, i have to store there result from subtraction of two field, which is also string field.The problem i am getting is that, when the result is coming negative i.e (500012 - 800012) = -300000, the result is(-300000), its more than 6 digit,because of negative sign, and due to that the result is not storing.Can you please provide me the best solution for this.Thanks.Abhi |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-07-10 : 05:15:56
|
First of all, don't use string data type to store numeric data, and if at all, you insist on storing data as string, then you will have to increase length to accomodate negative sign.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2008-07-10 : 06:26:52
|
IS it not possible o truncate the result up to six digit?if yes then how its possible? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-10 : 06:47:41
|
quote: Originally posted by abhit_kumar IS it not possible o truncate the result up to six digit?if yes then how its possible?
you can use SUBSTRING(field,2,6) to avoid the - sign. But always its better to use correct datatype for field. |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-07-10 : 06:51:14
|
quote: Originally posted by abhit_kumar IS it not possible o truncate the result up to six digit?if yes then how its possible?
Why not, but would that be correct output?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-10 : 07:05:26
|
quote: Originally posted by abhit_kumar IS it not possible o truncate the result up to six digit?if yes then how its possible?
The best approach is, as said, using the proper DATATYPE to store dataMadhivananFailing to plan is Planning to fail |
 |
|
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2008-07-10 : 07:06:37
|
I want the result that it include negative sign, not exclude negative sign like -30000, for temparory fix up |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-07-10 : 07:14:35
|
quote: Originally posted by abhit_kumar I want the result that it include negative sign, not exclude negative sign like -30000, for temparory fix up
Temporary fix up would do the permanent damage, mate!It would be good to change your table data type or size, if you don't want messy code in future.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
abhit_kumar
Posting Yak Master
147 Posts |
Posted - 2008-07-10 : 08:28:35
|
Yeah i know, but for a now, i wana fix up for this |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-10 : 09:11:28
|
quote: Originally posted by abhit_kumar Yeah i know, but for a now, i wana fix up for this
Increase the length of the columnMadhivananFailing to plan is Planning to fail |
 |
|
|