Skip to content

Instantly share code, notes, and snippets.

@zaagan
Last active August 3, 2019 04:52
Show Gist options
  • Save zaagan/5984fe70c5ed067fd5b1934058af6991 to your computer and use it in GitHub Desktop.
Save zaagan/5984fe70c5ed067fd5b1934058af6991 to your computer and use it in GitHub Desktop.
MS SQL Control Of Flow - If Else
-- 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