1 -- ---------------------------------- 2 -- Purpose: query the list. The first few or all entries are returned. 3 -- Project name: 4 -- Note: 5 -- Time: 12:16:41 6 -- ---------------------------------- 7 Alter Procedure [ DBO ] . [ Gettoplist_pro ] 8 @ Tbname Varchar ( 30 ), 9 @ Cols Varchar ( 400 ), 10 @ Top Int = 0 , 11 @ Strwhere Varchar ( 1000 ) = '' , 12 @ Orderby Varchar ( 1000 ) = '' 13 As 14 Declare @ Strtop Varchar ( 30 ) = '' 15 If @ Strwhere ! = '' 16 Set @ Strwhere = N ' Where ' + @ Strwhere 17 18 If @ Orderby ! = '' 19 Set @ Orderby = N ' Order ' + @ Orderby 20 21 If @ Cols = '' 22 Set @ Cols = N ' * ' 23 24 If @ Top > 0 25 Set @ Strtop = N' Top ' + Convert ( Varchar , @ Top ) 26 27 /* Set nocount on */ 28 Exec (N ' Select ' 29 + N ' ' + @ Strtop 30 + N ' ' + @ Cols 31 + N ' From ' + @ Tbname 32 + N ' ' + @ Strwhere 33 + N ' ' + @ Orderby ) 34 35 36 Print N ' Select ' 37 + N ' ' + @ Strtop 38 + N ' ' + @ Cols 39 + N ' From ' + @ Tbname 40 + N ' ' + @ Strwhere 41 + N ' ' + @ Orderby 42 Return