Quiz: TSQL Assignment Operator Fun

Quiz: TSQL Assignment Operator Fun ☎

We all know the equals sign. But did you know that in SQL Server 2008+, you can combine the assignment operator with other operators?
  • DECLARE @x numeric(3,1) = 1;
    SELECT @x += 3;
    SELECT @x as result;
    GO
  • DECLARE @x nvarchar(19) = N'Kendar';
    SELECT @x += N' loves doggos';
    SELECT @x as result;
    GO
  • DECLARE @x nvarchar(19) = N'Kendar';
    SELECT @x += (N' really' + N' loves doggos');
    SELECT @x as result;
    GO
  • DECLARE @x varchar(19) = 'doggos';
    SELECT @x -= 'doggo';
    SELECT @x as result;
    GO
  • DECLARE @x INT = 38;
    SELECT @x %= 5;
    SELECT @x as result;
    GO

Did you love this quiz? Did you hate it?

Either way, tweet it to @theogor and ! This quiz is all their fault. (Blame the modulo question on .)