IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Introduction to SQL Server

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

-- Declare the variable @region, and specify the data type of the variable
Modifica ed esegui il codice