SQL Server stored procedure review (i)

Source: Internet
Author: User

1--Stored Procedure Learning Chapter2 3--1simple stored procedures with no parameters for learning4IF object_id ('orders_getallorders','P') is not NULL5 DROP PROCEDURE orders_getallorders;6 GO7 CREATE PROC orders_getallorders8  as9 SET NOCOUNT on;TenSELECT *From dbo. Orders One GO A  ---2. Simple stored procedure with parameters -IF object_id ('Orders_getallbyname','P') is not NULL the DROP PROCEDURE orders_getallbyname; - GO - CREATE PROCEDURE orders_getallbyname -@ShipName NVARCHAR ( +) +  as -SELECT *From dbo. Orders +WHERE shipname=@ShipName A GO at  ---executing a stored procedure with parameters -EXEC orders_getallbyname @ShipName =n'Hanari Carnes' -  -  ---3. Using a simple stored procedure with wildcard parameters in  -IF object_id ('Employees_getallbyname','P') is not NULL to DROP PROCEDURE employees_getallbyname; + GO - CREATE PROCEDURE employees_getallbyname the@FirstName NVARCHAR (Ten) =n'%', *@LastName NVARCHAR ( -) =n'D%' $  asPanax NotoginsengSELECT *From dbo. Employees - WHERE FirstName like @FirstName and LastName like @LastName; the  +--Executing stored procedures AEXECUTE dbo. Employees_getallbyname @FirstName = N'Nancy',--nvarchar (Ten) the@LastName = N'Davolio'--nvarchar ( -) +  -  $--4. Returning multiple result sets $IF object_id ('Getmanyresultscount','P') is not NULL - DROP PROCEDURE getmanyresultscount; - GO the CREATE PROCEDURE Getmanyresultscount -  asWuyiSELECT COUNT (*) from dbo. Orders; theSELECT COUNT (*) from dbo. Employees; - GO Wu  ---Executing stored procedures About EXEC Getmanyresultscount; $  ---stored procedures that use the OUTPUT parameter -IF object_id ('getmanyproducts','P') is not NULL - DROP PROCEDURE getmanyproducts; A DOC + CREATE PROCEDURE getmanyproducts the@ProductName NVARCHAR ( +), - @MaxPrice Money, $ @ComparePrice Money OUTPUT, the @UnitPrice Money OUTPUT the  as the SELECT p.productname,p.unitprice from dbo. Products as P theINNER JOIN dbo. Categories as C on C.categoryid =P.categoryid -WHERE p.productname like @ProductName and p.unitprice<@MaxPrice in  the--Setting output Parameters theSET @UnitPrice =( About SELECT MAX (p.unitprice) from dbo. Products as P theJOIN dbo. Categories as C on C.categoryid =P.categoryid theWHERE p.productname like @ProductName and p.unitprice<@MaxPrice the ) +SET @[email protected];

SQL Server stored procedure review (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.