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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem in subtraction of String

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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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?
Go to Top of Page

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.
Go to Top of Page

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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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 data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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
Go to Top of Page

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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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
Go to Top of Page

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 column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -