Mature SQL paging storage process (UP_General_SelectByWhere)

Source: Internet
Author: User
View Code

1 GO
2/***** Object: StoredProcedure [dbo]. [UP_General_SelectByWhere] Script Date: 03/17/2011 10:49:23 ******/
3 SET ANSI_NULLS ON
4 GO
5 SET QUOTED_IDENTIFIER ON
6 GO
7 -- ============================================== ========
8 -- Author: <Author, Name>
9 -- Create date: <Create Date,>
10 -- Description: <Description,>
11 -- ============================================== ========
12 alter procedure [dbo]. [UP_General_SelectByWhere]
13 (
14 @ strSelect NVarChar (1000 ),
15 @ strWhere NVarChar (4000 ),
16 @ strTable NVarChar (50 ),
17 @ strorder1_nvarchar (100 ),
18 @ OrderType bit = 0
19)
20
21 BEGIN
22 DECLARE @ strSQL varchar (8000) -- subject sentence
23 DECLARE @ strOrder varchar (400) -- sort type
24 IF (@ strOrderfld! = '')
25 BEGIN
26 if @ OrderType! = 0 -- descending order (desc)
27 BEGIN
28 set @ strOrder = 'ORDER BY' + @ strOrderfld + 'desc' -- If @ OrderType is not 0, execute the descending order. This sentence is very important!
29 END
30 ELSE -- Ascending (asc)
31 BEGIN
32 set @ strOrder = 'ORDER BY' + @ strOrderfld + 'asc'
33 END
34 SET @ strSQL = 'select' + @ strSelect + 'from' + @ strTable + 'where 1 = 1' + @ strWhere + @ strOrder
35 END
36 ELSE
37 BEGIN
38 SET @ strSQL = 'select' + @ strSelect + 'from' + @ strTable + 'where 1 = 1' + @ strWhere
39 END
40 EXECUTE (@ strSQL)
41 END

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.