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
 Transact-SQL (2000)
 unexpected SP Query results

Author  Topic 

swanagetown
Starting Member

19 Posts

Posted - 2005-04-04 : 08:50:02
Hi,

I can't understand why this doesn't work:

CREATE PROCEDURE LTV
(@Loan Int, @PropVal Int)
AS
Declare @LTV decimal
set @LTV = CONVERT(decimal, @Loan) / CONVERT(decimal, @PropVal)

SELECT *
FROM TABLE1
WHERE LTV >= @LTV
GO

The LTV column contains date like 0.5, 0.65, 0.80 etc...
It works provided the @LTV calculation is less than 0.50 but not if it's above. To test where this is going wrong I changed "WHERE LTV >= @LTV" to "WHERE LTV >= 0.79" and it worked fine, just returned the 0.80 data. Why doesn't it like "set @LTV = CONVERT(decimal, @Loan) / CONVERT(decimal, @PropVal)"?

mr_mist
Grunnio

1870 Posts

Posted - 2005-04-04 : 08:54:27
You're taking the values in as INTs, so you will lose any fractional parts.

Declare them as decimals in the procedure declaration.

-------
Moo. :)
Go to Top of Page

swanagetown
Starting Member

19 Posts

Posted - 2005-04-04 : 09:44:17
Thanks.

That work nicely :)
Go to Top of Page
   

- Advertisement -