Chapter 6 PROGRAMMING SQL SERVER 2000 339 What s
Chapter 6 PROGRAMMING SQL SERVER 2000 339 What s the difference? There are three major differences. First, the SELECT statement returns a rowset, whereas the PRINT statement just prints out a string. So, the PRINT statement can just put the string into the output stream, but the SELECT statement can be used by applications. Second, a PRINT statement doesn t necessarily happen in sequence with the rest of a batch, and actually, PRINT statements usually aren t executed until the end of the batch or if there s a PRINT statement pending and the value needs to be changed. This happens only with very long and complicated batches, but can make debugging difficult. Finally, a SELECT statement returns any data you want, whereas a PRINT can return only the data that can be converted into strings directly. You cannot use PRINT with a function call or with anything else that cannot be implicitly converted to a string type. So, say that you have a variable with the string 42 in it. Not the number 42, but the string 42 . Here s an example: DECLARE @TestValue varchar(30), @TestResult int SET @TestValue = 42 SET @TestResult = @TestValue + 3 PRINT @TestResult This code will print the value 45, because it automatically converted the string value 42 to the integer value 42 and then added 3. Now look at this example: DECLARE @TestValue varchar(30), @TestResult int SET @TestValue = 42 SET @TestResult = @TestValue + 3 PRINT @TestResult This prints out the value 423, because it takes the string 42 and adds the character 3 onto the end. To prevent confusion from these situations, it s best to use the convert function to convert values to the type for their result. In other words, do something like this: DECLARE @TestValue varchar(30), @TestResult int SET @TestValue = 42 SET @TestResult = convert(int, @TestValue) + 3 PRINT @TestResult This produces the same result, but it s easier to figure out exactly what s going on because there s no ambiguity that it might return 423 or the number 45. The plus sign is used for both string concatenation and addition.
For high quality java hosting services please check tomcat web hosting website.