'Float as data types and comparing variables from them
I have following SQL code for stored procedure, and I am not sure why IF statement logic would not work.
When I run select statement for both variable (@state & @mostrecent), both values are same.
But, even though the values are same, it still inserts data.
Is there any syntax error?
How do I only indicate only "IF", not "ELSE" as well?
BEGIN
DECLARE @stage_total float,
@mostrecent_total float;
set @stage_total =
(
select sum(Current_Amount) from
[dbo].[tblPayCorEarnings_Staging]
);
set @mostrecent_total =
(
select sum(Current_Amount) from
[dbo].[tblPayCorEarnings_Prod]
where DateLoad in (select distinct top 1 DateLoad from [dbo].[tblPayCorEarnings_Prod] order by DateLoad desc)
);
IF (@stage_total <> @mostrecent_total)
begin
begin
insert into [dbo].[tblPayCorEarnings_Prod]
select * from [dbo].[tblPayCorEarnings_Staging]
end
end
END
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|