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
 General SQL Server Forums
 New to SQL Server Programming
 SUBTRACT ISSUE

Author  Topic 

Rigoberto
Starting Member

7 Posts

Posted - 2011-04-15 : 09:13:05
Hi there,

Anybody could help me with a Simple subtract issue:


i have this formula

Field1 - Filed2

10 - 5 = 5
10 - 0 = 0

how can you see the result of sample 2 is 0, why?
I am running a Sql statement and using some database field and the result when the second field is equal 0 is 0?

By the way Field1 is Int and the second one is numeric, could be the problem related with the Field atribute?




raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-04-15 : 09:25:59
which version of sql you are using
if possible send some sample data and your query

Raghu' S
Go to Top of Page

Rigoberto
Starting Member

7 Posts

Posted - 2011-04-15 : 09:36:34

SQL SERVER 2008, here is a sample of the sql statement

Select (Field1-Field2) From Table1
Go to Top of Page

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-04-15 : 09:42:56
Hey what is range of your second field Field2 numeric(,)

Raghu' S
Go to Top of Page

Rigoberto
Starting Member

7 Posts

Posted - 2011-04-15 : 09:48:45
hey,

Field1(Integer) and Field2(Numeric)

Field1 is Integer
Field2 is Numeric

Rg
Go to Top of Page

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-04-15 : 09:54:20
Hey try this and tell me what output you getting either same or

create table #t(Field1 int, Field2 numeric)
insert into #t
select 10,5 union all
select 10,0 union all
select 0,10

select (Field1-Field2)as summ from #t



Raghu' S
Go to Top of Page

Rigoberto
Starting Member

7 Posts

Posted - 2011-04-15 : 09:57:43
Thanks Raghu' S, just I have solved my problem, what I did?


well I have used the function convert() to convert my Interger field to numeric, jsut it is woking now

Thanks a lot all you guys for your help!!
Go to Top of Page
   

- Advertisement -