Common SQL Server Stored Procedures

Source: Internet
Author: User
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 

 

 

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.