Local variables and update statements  Local variables and while loops and if…else blocks

Chapter 14: Using Batches and Control-of-Flow Language

Local variables and subqueries

A subquery that assigns a value to the local variable must return only one value. Here are some examples:

declare @veryhigh money 
select @veryhigh = max(price) 
   from titles 
if @veryhigh > $20 
   print "Ouch!" 
declare @one varchar(18), @two varchar(18) 
select @one = "this is one", @two = "this is two" 
if @one = "this is one" 
   print "you got one" 
if @two = "this is two" 
   print "you got two" 
else print "nope" 
declare @tcount int, @pcount int 
select @tcount = (select count(*) from titles), 
   @pcount = (select count(*) from publishers) 
select @tcount, @pcount 




Copyright © 2005. Sybase Inc. All rights reserved. Local variables and while loops and if…else blocks

View this book as PDF