0% found this document useful (0 votes)
12 views

Relational Operators

Uploaded by

Pawan Dhail
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Relational Operators

Uploaded by

Pawan Dhail
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Relational Operator

SELECT [EmployeeID]
,[Rate]
,[PayFrequency]
FROM [AdventureWorks].[HumanResources].[EmployeePayHistory]
WHERE Rate >15;
GO

=====================================================================
IF- ELSE
DECLARE @DateHired As datetime2,
@CurrentDate As datetime2
SET @DateHired = N'2010/10/04'
SET @CurrentDate = SYSDATETIME()
IF @DateHired < @CurrentDate
BEGIN
PRINT 'You have the experience required for a new promotion '
PRINT @DateHired
END
ELSE
PRINT 'You do not have the experience required for a new promotion '
GO

----------------------------------
-- 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 N'You must provide a positive value';
GO

=====================================================================
CASE WHEN THEN ELSE

DECLARE @CharGender Char(1),


@Gender Varchar(20);
SET @CharGender = N'g';
SET @Gender =
CASE @CharGender
WHEN 'm' THEN 'Male'
WHEN 'M' THEN 'Male'
WHEN 'f' THEN 'Female'
WHEN 'F' THEN 'Female'
ELSE 'Unknown'
END;
SELECT N'Student Gender: ' + @Gender;
GO
==================================================================
WHILE

DECLARE @Number As int


SET @Number = 1
WHILE @Number < 5
BEGIN
SELECT @Number AS Number
SET @Number = @Number + 1
END
GO

You might also like