Last active
August 3, 2019 04:52
-
-
Save zaagan/5984fe70c5ed067fd5b1934058af6991 to your computer and use it in GitHub Desktop.
MS SQL Control Of Flow - If Else
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Example 1 | |
IF DATENAME(weekday, | |
GETDATE()) IN (N'Saturday', N'Sunday') | |
SELECT 'Weekend'; | |
ELSE | |
SELECT 'Weekday'; | |
-- Example 2 | |
IF EXISTS(SELECT 1 | |
FROM Production.Product | |
WHERE Name = 'Blade') | |
BEGIN | |
SELECT 'I have a blade.'; | |
END | |
ELSE | |
BEGIN | |
SELECT 'I don`t have a blade'; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment