Transact-SQL Expressions: IS |
|
Introduction |
To validate something as being possible, you can use the IS operator. For example, to acknowledge that something is NULL, you can use the IS NULL expression. Here is an example: -- Square Calculation DECLARE @Side As Decimal(10,3), @Perimeter As Decimal(10,3), @Area As Decimal(10,3); SET @Perimeter = @Side * 4; SET @Area = @Side * @Side; IF @Side IS NULL PRINT 'A null value is not welcome' ELSE IF @Side > 0 BEGIN SELECT @Side AS Side; SELECT @Perimeter AS Perimeter ; SELECT @Area AS Area; END; ELSE PRINT N'You must provide a positive value'; GO This would produce: To avoid having a NULL value, you can either initialize the variable or you can assign it a value. Here is an example: -- Square Calculation DECLARE @Side As Decimal(10,3), @Perimeter As Decimal(10,3), @Area As Decimal(10,3); SET @Side = 48.126; SET @Perimeter = @Side * 4; SET @Area = @Side * @Side; IF @Side IS NULL PRINT N'A null value is not welcome' ELSE IF @Side > 0 BEGIN SELECT @Side AS Side; SELECT @Perimeter AS Perimeter ; SELECT @Area AS Area; END; ELSE PRINT 'You must provide a positive value'; GO This would produce: |
|
||
Home | Copyright © 2007-2009 FunctionX, Inc. | |
|