SQL Server Chinese capital amount Conversion Function

Source: Internet
Author: User
/*   
Function Name: sp_getrecordfrompage
Function: obtains data on a specified page.
Parameter description: @ tblname indicates the name of the table containing data.
@ Fldname key field name
@ Pagesize number of records per page
@ Pageindex: page number to be obtained
@ Ordertype: Sorting type. Values: 0 (ascending) and 1 (descending ).
@ Strwhere query condition (Note: Do not add the where value '')
*/
Create Procedure Sp_getrecordfrompage
@ Tblname Varchar ( 255 ), -- Table Name
@ Fldname Varchar ( 255 ), -- List of field names to be sorted. Multiple fields are separated by commas.
@ Pagesize Int = 10 , -- The default page size is 10.
@ Pageindex Int = 1 , -- The default page size is 1.
@ Ordertype Bit = 0 , -- Set the sorting type. If the value is not 0, sort it in descending order.
@ Strwhere Varchar (2000 ) = '' -- Query conditions (Note: Do not add where)
As

Declare @ Strsql Varchar ( 6000 ) -- Subject sentence
Declare @ Strtmp Varchar ( 1000 ) -- Temporary Variable
Declare @ Strorder Varchar ( 500 ) -- Sorting type

If @ Ordertype ! = 0
Begin
Set @ Strtmp = ' <(Select Min '
Set @ Strorder = ' Order [ ' + @ Fldname + ' ] DESC '
End
Else
Begin
Set @ Strtmp = ' > (Select Max '
Set @ Strorder = ' Order ' + @ Fldname + ' ASC '
End

Set @ Strsql = ' Select top ' + Str ( @ Pagesize ) + ' * From [ '
+ @ Tblname + ' ] Where [ ' + @ Fldname + ' ] ' + @ Strtmp + ' ([ '
+ @ Fldname + ' ]) From (select top ' + Str (( @ Pageindex - 1 ) * @ Pagesize ) + ' [ '
+ @ Fldname + ' ] From [ ' + @ Tblname + ' ] ' + @ Strorder + ' ) As tbltmp) '
+ @ Strorder

If @ Strwhere ! = ''
Set @ Strsql = ' Select top ' + Str ( @ Pagesize ) + ' * From [ '
+ @ Tblname + ' ] Where [ ' + @ Fldname + ' ] ' + @ Strtmp + ' ([ '
+ @ Fldname + ' ]) From (select top ' + Str (( @ Pageindex - 1 ) * @ Pagesize ) + ' [ '
+ @ Fldname + ' ] From [ ' + @ Tblname + ' ] Where ' + @ Strwhere + ' '
+ @ Strorder + ' ) As tbltmp) and ' + @ Strwhere + ' ' + @ Strorder

If @ Pageindex = 1
Begin
Set @ Strtmp = ''
If @ Strwhere ! = ''
Set @ Strtmp = ' Where ( ' + @ Strwhere + ' ) '

Set @ Strsql = ' Select top ' + Str ( @ Pagesize ) + ' * From [ '
+ @ Tblname + ' ] ' + @ Strtmp + ' ' + @ Strorder
End

Exec ( @ Strsql )

Go
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.