334 Part I EXAM PREPARATION WORKING WITH VARIABLES
334 Part I EXAM PREPARATION WORKING WITH VARIABLES A variable is a temporary place to put pieces of data that you re working with. This can include things such as dates, numbers for counting with, or strings that you need to manipulate. SQL Server is a language that could be termed strongly typed ; that is, it has several different types of variables, and there are certain restrictions on converting from one type to another. With respect to variables, you need to understand six topics: Naming variables Declaring variables Variable types Variable scope Setting and using variables Global variables The first thing to understand is how variables are named. Naming Variables A variable follows the same naming scheme as a column name, with one slight addition. One of the big problems that SQL Server has is determining which part of a statement is a variable and which is a column name. If, for example, you have a variable that contains an object ID, and you want to find the name of the object, things might get very confusing: SELECT name FROM sysobjects WHERE id = id That statement returns all the rows in the sysobjects table (id is always equal to id, after all). That s probably not what you intended to do, but it s a common mistake. So, to allow SQL Server to make the connection between ID the column and ID the variable, you always have to put an at sign (@) in front of a variable name. So, the preceding statement becomes SELECT name FROM sysobjects WHERE id = @ID
For high quality java hosting services please check tomcat web hosting website.