Wednesday, June 29, 2016

if condition in sql server 2008



if condition in sql

CREATE FUNCTION [dbo.[fnc_ValidateMilageReadings]
(
   @round_id INT,
   @depot_id INT,
)
RETURNS BIT

AS
BEGIN

DECLARE @openMilage NVARCHAR
DECLARE @firstStopMilage NVARCHAR
DECLARE @lastStopMilage NVARCHAR
DECLARE @closeMilage NVARCHAR
DECLARE @returnValue BIT

SET @returnValue = 0

SELECT @openMilage  = openMilage, @firstStopMilage = firstStopMilage, @lastStopMilage = lastStopMilage
FROM Transaction
WHERE roundId = @round_id AND depotId = @depot_id

IF (@closeMilage IS NULL) BEGIN SET @returnValue  = 0 END
ELSE IF (@closeMilage  = 0)  BEGIN SET @returnValue  = 0 END
ELSE IF @openMilage  < firstStopMilage BEGIN SET @returnValue  = 0 END
ELSE IF @firstStopMilage  < @lastStopMilage  BEGIN SET @returnValue  = 0 END
ELSE IF @lastStopMilage  < @closeMilage BEGIN SET @returnValue  = 0 END
ELSE @returnValue  = 1

RETURN @returnValue

END


No comments:

Post a Comment