T-SQL row to column, database query paging

Source: Internet
Author: User

 1 use [aps_future_ft] 2 GO 3/****** object:storedprocedure [dbo].    [A_crudeprice] Script DATE:2013/11/5 19:13:21 ******/4 SET ANSI_NULLS on 5 go 6 SET QUOTED_IDENTIFIER on 7 Go 8--==================== ========================= 9--Author: <author,,name>10--Create Date: <create date,,>11--Descriptio N: <description,,>12--=============================================13 ALTER PROCEDURE [dbo]. [A_crudeprice]14 (@BeginDate DATETIME, @EndDate datetime,17 @PageSize int,18 @PageIndex INT, @TotalCount INT OUTPUT20) AS22 BEGIN23--SET NOCOUNT on added to prevent extra result sets From24-- Interfering with SELECT statements.25 SET NOCOUNT on;26 DECLARE @CodeList NVARCHAR (max) DECLARE @str NVAR CHAR (max) SET @CodeList = (SELECT DISTINCT ' [' + ISCP. Crudestandard+ '], ' from dbo.         T_h_internalstandardcrudeprice iscp31 for XML PATH (") 32            ) SET @CodeList = SUBSTRING (@CodeList, 1,len (@CodeList)-1) PRINT @CodeList35 Iscp. PRICEDATE,ISCP. CRUDESTANDARD,ISCP. CrudeStandardPrice37 to #A38 from dbo. T_h_internalstandardcrudeprice iscp39 WHERE ISCP. Pricedate between @BeginDate and @EndDate40 SET @str = ' Row=row_number () over (order by pricedate Desc) , Pricedate, ' [email protected]+ ' from (#A46) as A47 PIVOT (SUM (A.crud            Estandardprice) for A.crudestandard in (' [email protected]+ ') "as B '," SET @str = ' SELECT * into # #A50 From (' [email protected]+ ') as C ' (@str), SELECT * from # #A as tempA56 WHE RE Tempa.row between @PageSize * @PageIndex and @PageSize * (@PageIndex + 1) * * * @TotalCount = (select COUNT (*) From # #A60) drop table #A62 drop table # #A63

T-SQL row to column, database query paging

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.