Monday, 12 December 2011

How To Create Stored Procedure in T-Sql



CREATE PROCEDURE SalesQtys
3> @chvOrderBy VARCHAR(30) = 'qty',
4> @chvSortType VARCHAR(4) = 'ASC'
5> AS
6> DECLARE @chvSQL VARCHAR(255)
7> SELECT @chvSQL = 'SELECT stor_id, ord_num, title_id, qty'
8> SELECT @chvSQL = @chvSQL + ' FROM Sales'
9> SELECT @chvSQL = @chvSQL + ' ORDER BY ' + @chvOrderBy + ' ' + @chvSortType
10> EXEC (@chvSQL)
11> GO

No comments:

Post a Comment