techques
asked on
How to fix this query?
ALTER FUNCTION [dbo].[Func_Bank_Balance]
(
@accountid int,
@addoneday datetime
)
Returns decimal(18,4)
AS
BEGIN
Declare @return decimal(18,4)
Declare @return1 decimal(18,4)
Declare @bal int
select @bal=a.balance from account a where a.id=@accountid
if @bal is null
set @bal = 0
select @return1 = sum(amount + countervalue) from alltransaction
where accountid=@accountid and trandatetime < @addoneday and accountid > 0
if @return1 is null
set @return1 = 0
set @return = @bal + @return1
return @return
END
The result of
select a.balance from account a where a.id='12148'
2.82
The result of
select sum(amount + countervalue) from alltransaction where accountid='12148' and trandatetime < '2009-12-06 06:00:00' and accountid > 0
null
The result of
Select dbo.Func_Bank_Balance('121 48', '2009-12-06 06:00:00') accountbal from alltransaction t where t.trandatetime < '2009-12-06 06:00:00'
2.0000
It is wrong, it should be 2.8200
How should I fix it?
(
@accountid int,
@addoneday datetime
)
Returns decimal(18,4)
AS
BEGIN
Declare @return decimal(18,4)
Declare @return1 decimal(18,4)
Declare @bal int
select @bal=a.balance from account a where a.id=@accountid
if @bal is null
set @bal = 0
select @return1 = sum(amount + countervalue) from alltransaction
where accountid=@accountid and trandatetime < @addoneday and accountid > 0
if @return1 is null
set @return1 = 0
set @return = @bal + @return1
return @return
END
The result of
select a.balance from account a where a.id='12148'
2.82
The result of
select sum(amount + countervalue) from alltransaction where accountid='12148' and trandatetime < '2009-12-06 06:00:00' and accountid > 0
null
The result of
Select dbo.Func_Bank_Balance('121
2.0000
It is wrong, it should be 2.8200
How should I fix it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@bal decimal(18,4) yes, it has fixed
Select dbo.Func_Bank_Balance(a.ba
from alltransaction t
where t.trandatetime < '2009-12-06 06:00:00'