1. Declare declare @discount float set @discount = 10 select * from customers where discnt > @discount
2. Get values from the select result declare @mindiscount float select @mindiscount = min(discnt) from customers
3. Display the result (in 2, the output is disabled, nothing is displayed) select @mindiscount as DISCOUNT
4. @@ROWCOUNT Returns the number of rows affected by the last statement. (When you do the programming, you need to know there are how many records in the query resutls) select * from customers select @@rowcount as RowCounter insert customers values ('c019', 'Heller', 'Rebecca', 12) select @@rowcount as RowCounter update customers set name = 'Jones' where cid = 'c020' If @@ROWCOUNT = 0 print 'Warning: No rows were updated'
5. Begin... End / If... Else / Continue / Break declare @v1 int, @v2 int set @v1 = 0 set @v2 = 100 while (@v1 < 10) begin if(@v2 % 2 = 0) set @v2 = @v2 + 1 else set @v2 = @v2 + 2 set @v1 = @v1 + 1 end select @v1 as v1, @v2 as v2
5. Begin... End / If... Else / Continue / Break (cont) declare @v1 int, @v2 int set @v1 = 0 set @v2 = 100 while (@v1 < 10) begin if(@v1 = 5) break else set @v2 = @v2 + 2 set @v1 = @v1 + 1 end select @v1 as v1, @v2 as v2
6. Case (alias) select cname, category = case when discnt < 8 then 'low' when discnt between 8 and 10 then 'med' else 'high' end from customers
8. Go Signals the end of a batch of Transact-SQL statements to the Microsoft® SQL Server™ utilities declare @mindiscount float select @mindiscount = min(discnt) from customers select @mindiscount GO select @mindiscount //@mindiscount is not defined after 'GO'