Presentation on theme: "Transact-SQL. 1. Declare float = 10 select * from customers where discnt"— Presentation transcript:
1. Declare float = 10 select * from customers where discnt
2. Get values from the select result float = min(discnt) from customers
3. Display the result (in 2, the output is disabled, nothing is displayed) as DISCOUNT
4. 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 as RowCounter insert customers values ('c019', 'Heller', 'Rebecca', 12) select as RowCounter update customers set name = 'Jones' where cid = 'c020' If = 0 print 'Warning: No rows were updated'
5. Begin... End / If... Else / Continue / Break int = 0 = 100 while < 10) begin % 2 = 0) + 1 else end as as v2
5. Begin... End / If... Else / Continue / Break (cont) int = 0 = 100 while < 10) begin = 5) break else end as 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
7. Print varchar(32) = 'Hello' //Also try
8. Go Signals the end of a batch of Transact-SQL statements to the Microsoft® SQL Server™ utilities float = min(discnt) from customers GO is not defined after 'GO'
9. Operators +, -, *, /, % =,, =, !=, !>, !<
10. Data types int, smalling, char(n), varchar(n), money, float
11.1 Stored procedure - create 1. create proc char(4) as select cname from customers where cid go 2. Exec get_customer SELECT CID FROM CUSTOMERS ’
11.2 help/delete 1. check the interface sp_help get_customer 2. check the source code sp_helptext get_customer 3. delete drop proc get_customer
11.3 different return results create proc myproc1 as int = 1 return create proc myproc2 as int = 1 return
11.4 return multiple datasets create proc myproc3 as select * from customers select * from agents return
11.5 multiple input parameters create proc int as select * from customers where discnt select * from agents where percentage return exec myproc4 15,5
11.6 return values create proc int output as = count(*) from customers where discnt return int exec myproc5 output
11.6 return values - cont create proc int output as select * from customers where discnt = return int exec myproc6 output
11.6 return values - cont create proc int int output as select * from customers = select * from agents = return int exec
12. UDF (user-defined funcation) create function char(4)) returns money as begin money = avg(dollars) from orders where cid end sp_help average_dollars sp_helptext average_dollars
12. UDF - cont float = zhoupf.average_dollars('c001') *Inside UDF, don’t make any changes to tables. *Difference between UDF and stored procedure.