Stored procedure can be executed with the parameter and assigned value : Create Procedure « Store Procedure Function « SQL Server / T-SQL

SQL Server / T-SQL
1. Aggregate Functions
2. Analytical Functions
3. Constraints
4. Cursor
5. Data Set
6. Data Type
7. Database
8. Date Timezone
9. Index
10. Insert Delete Update
11. Math Functions
12. Select Query
13. Sequence
14. Store Procedure Function
15. String Functions
16. Subquery
17. System
18. Table
19. Table Joins
20. Transact SQL
21. Transaction
22. Trigger
23. View
24. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL » Store Procedure Function » Create Procedure 
Stored procedure can be executed with the parameter and assigned value

 


2>
3>
4CREATE TABLE Product(
5>     ProductID               int                NOT NULL,
6>     Name                    nvarchar(25)       NOT NULL,
7>     ProductNumber           nvarchar(25)               ,
8>     Color                   nvarchar(15)       NULL,
9>     StandardCost            money              NOT NULL,
10>     Size                    nvarchar(5)        NULL,
11>     Weight                  decimal(82)      NULL,
12>     ProductLine             nchar(20)           NULL,
13>     SellStartDate           datetime           NOT NULL,
14>     SellEndDate             datetime           NULL
15)
16> GO
1insert into Product values(1,'Product A', '1','Red',123.123,'1',1,'ProductLine A','1999-03-22','2000-03-22');
2> GO

(rows affected)
1insert into Product values(2,'Product B', '2','Yellow',234.234,'1',3,'ProductLine B','2000-03-22','2001-03-22');
2> GO

(rows affected)
1insert into Product values(3,'Product C', '3','Pink',345.345,'1',3,'ProductLine V','2001-09-22','2006-02-22');
2> GO

(rows affected)
1insert into Product values(4,'Product D', '4','White',456.456,'1',4,'ProductLine D','2002-08-22','2006-03-22');
2> GO

(rows affected)
1insert into Product values(5,'Product E', '5','Black',567.567,'1',5,'ProductLine E','2003-01-22','2003-04-22');
2> GO

(rows affected)
1insert into Product values(6,'Product F', '6','Blue',678.678,'1',6,'ProductLine W','2004-02-22','2005-05-22');
2> GO

(rows affected)
1insert into Product values(7,'Product G', '7','Drak',789.789,'1',7,'ProductLine Q','2005-03-22','2006-03-22');
2> GO

(rows affected)
1insert into Product values(8,'Product H', '8','Gray',234.123,'1',8,'ProductLine F','2006-04-22','2006-09-22');
2> GO

(rows affected)
1insert into Product values(9,'Product I', '9','Red',543.123,'1',9,'ProductLine R','2007-05-22','2008-03-22');
2> GO

(rows affected)
1insert into Product values(0,'Product J', '0','Gold',765.123,'1',0,'ProductLine J','2008-06-22','2009-03-22');
2> GO

(rows affected)
1>
2>
3> Create PROCEDURE spProductCosts
4> @SubID Int
5> AS
6SELECT ProductID, Name, ProductNumber, StandardCost FROM Product
7WHERE ProductID = @SubID
8> GO
1>
2>
3> EXECUTE spProductCosts 1
4> GO
ProductID   Name                      ProductNumber             StandardCost
----------- ------------------------- ------------------------- ---------------------
          Product A                 1                                      123.1230

(rows affected)
1>
2
3> EXECUTE spProductCosts @SubCategory = 1
4> GO
HResult 0xC9, Level 16, State 4
Procedure or Function 'spProductCosts' expects parameter '@SubID', which was not supplied.
1>
2> drop  PROCEDURE spProductCosts;
3> GO
1>
2>
3> drop table Product;
4> GO

 
Related examples in the same category
1. Performing Data Manipulation: Adding a New Row
2. Returning a Single Result Set from a procedure
3. Check to see if a procedure exists
4. Define procedure to insert or update
5. Store Procedure: Returns the Customer record given a parameter of the ID
6. Store procedure: pre-check for the existence of the foreign key (RegionID) before attempting the insert
7. Processing Return Status Values
8. Return only one value from the procedure: without the use of an output parameter
9. Using Parameters
10. Stored Procedures as Parameterized Views
11. RECOMPILE(ing) a Stored Procedure Each Time It Is Executed
12. Transaction in a procedure
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.