Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transact-SQL. 1. Declare float = 10 select * from customers where discnt

Similar presentations


Presentation on theme: "Transact-SQL. 1. Declare float = 10 select * from customers where discnt"— Presentation transcript:

1 Transact-SQL

2 1. Declare float = 10 select * from customers where discnt

3 2. Get values from the select result float = min(discnt) from customers

4 3. Display the result (in 2, the output is disabled, nothing is displayed) as DISCOUNT

5 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'

6 5. Begin... End / If... Else / Continue / Break int = 0 = 100 while < 10) begin % 2 = 0) + 1 else end as as v2

7 5. Begin... End / If... Else / Continue / Break (cont) int = 0 = 100 while < 10) begin = 5) break else end as as v2

8 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

9 7. Print varchar(32) = 'Hello' //Also try

10 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'

11 9. Operators +, -, *, /, % =,, =, !=, !>, !<

12 10. Data types int, smalling, char(n), varchar(n), money, float

13 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 ’

14 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

15 11.3 different return results create proc myproc1 as int = 1 return create proc myproc2 as int = 1 return

16 11.4 return multiple datasets create proc myproc3 as select * from customers select * from agents return

17 11.5 multiple input parameters create proc int as select * from customers where discnt select * from agents where percentage return exec myproc4 15,5

18 11.6 return values create proc int output as = count(*) from customers where discnt return int exec myproc5 output

19 11.6 return values - cont create proc int output as select * from customers where discnt = return int exec myproc6 output

20 11.6 return values - cont create proc int int output as select * from customers = select * from agents = return int exec

21 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

22 12. UDF - cont float = zhoupf.average_dollars('c001') *Inside UDF, don’t make any changes to tables. *Difference between UDF and stored procedure.


Download ppt "Transact-SQL. 1. Declare float = 10 select * from customers where discnt"

Similar presentations


Ads by Google