Hi guys;
I need your assistance.
I am extracting some info from my database and I need difference between two fields of money values.
Lets call the fields as Field1,Field2,& Field3.

Field1 = Current Balance
Field2 = Starting Balance
Field3 = Field1 - Field2

From my query, I get Field3 as NULL. I cant understand what is wrong with my formula.

Here is the formula:

Declare @Field1 numeric (18,2),
        @Field2 numeric (18,2),
        @Field3 numeric (18,2)

Select Field1  = @Field1  , Field2 = @Field2
Select @Field3 = @Field1  - @Field2
Select @Field3

Please assist. TQ.

Recommended Answers

All 2 Replies

Look into parameterization with arithmetic operations.

Try this:

Select Field1 = CAST( @Field1 AS MONEY ), Field2 = CAST( @Field2 AS MONEY )

Look into parameterization with arithmetic operations.

Try this:

Select Field1 = CAST( @Field1 AS MONEY ), Field2 = CAST( @Field2 AS MONEY )

Thanks Samaru for your contribution.
I tried your hint you gave me but still did not give the results i expected, now field3 is rounding off to a whole figure instead of actual difference.

For example if field1 = 50.35 and field2=20.12, field3 should be 30.23 but its giving 30.

Any ideas why its rounding off??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.