Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Practice - Checking values in table/query to continue

Status
Not open for further replies.

PreacherUK

Technical User
Sep 26, 2002
156
0
0
NL
hi all,

I have a table/view (at this stage I'm running it as a view but figure I can make it a temp table in an sp) which is subtracting one field from another.

This will result in a value that, will hopefully be zero, give or take a tolerance of $5 in either direction.

Whats the best way of making a decision based on the result of that view/content of the table?

Ask the view to return to me all records that dont have a zero balance and check for that with the @@ROWCOUNT key word?

Or should I be using some code/logic along the line of IF (view returns nothing) then etc?


I've included the view here (for what its worth :) )

SELECT [OnLoan$From Stats] - [OnLoan$From Source] AS Onloan, [Accrued$From Stats] - [Accrued$From Source] AS Accrued

FROM dbo.TMPTABLECOMPARE
WHERE ([OnLoan$From Stats] - [OnLoan$From Source] > 5) AND ([Accrued$From Stats] - [Accrued$From Source] > 5)

OR ([OnLoan$From Stats] - [OnLoan$From Source] < - 5)
AND ([Accrued$From Stats] - [Accrued$From Source] < - 5)


Cheers
 
A procedure or function would be more elegant solution.
use this:
SELECT (value1-value2) as diff
FROM dbo.TMPTABLECOMPARE
WHERE ABS(value1 - value2) < 5
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top