DECLARE and SET a variable
Using variables makes it easy to run a query multiple times, with different values, without having to scroll down and amend the WHERE
clause each time. You can quickly update the variable at the top of the query instead.
This also helps provide greater security, but that is out of scope of this course.
Let's go back to the now very familiar grid
table for this exercise, and use it to practice extracting data according to your newly defined variable.
This exercise is part of the course
Introduction to SQL Server
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Declare the variable @region, and specify the data type of the variable