zaagan
8/3/2019 - 4:45 AM

MS SQL Control Of Flow - If Else

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