我有一个按钮,当点击时执行以下代码:
DECLARE @p0 NVarChar(4000) = 'SUCCESS'
DECLARE @p1 NVarChar(4000) = 'REMBOURS'
DECLARE @p2 NVarChar(4000) = 'AFTERPAY'
DECLARE @p3 Decimal(31,2) = '0'
DECLARE @p4 NVarChar(4000) = '-'
DECLARE @p5 DateTime = '2016-06-01'
DECLARE @p6 DateTime = '2016-09-01'
DECLARE @p7 Int = '4'
DECLARE @p8 Int = '5'
DECLARE @p9 Int = '8'
DECLARE @p10 NVarChar(4000) = 'SUCCESS'
DECLARE @p11 NVarChar(4000) = 'REMBOURS'
DECLARE @p12 NVarChar(4000) = 'AFTERPAY'
DECLARE @p13 NVarChar(4000) = '-'
DECLARE @p14 NVarChar(4000) = '-'
DECLARE @p15 Int = '2'
DECLARE @p16 NChar(1) = '0'
SELECT [t64].[value] AS [Month], [t64].[value2] AS [Count], [t64].[value22] AS [Total], [t64].[value3] AS [VAT]
FROM (
SELECT ((CONVERT(NVarChar,DATEPART(Year, (
SELECT [t23].[value]
FROM (
SELECT TOP (1) [t18].[value]
FROM (
SELECT (
SELECT [t17].[DateTime]
FROM (
SELECT TOP (1) [t15].[DateTime]
FROM [dbo].[OrderOrderPaymentStatus] AS [t15]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t16] ON [t16].[Id] = [t15].[OrderPaymentStatusId]
WHERE ([t16].[Code] IN (@p0, @p1, @p2)) AND ([t15].[OrderId] = [t14].[Id])
) AS [t17]
) AS [value], [t14].[Id]
FROM [dbo].[Order] AS [t14]
) AS [t18]
WHERE ((([t13].[value4] IS NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t18].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t18].[value])))) IS NULL)) OR (([t13].[value4] IS NOT NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t18].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t18].[value])))) IS NOT NULL) AND ([t13].[value4] = (((CONVERT(NVarChar,DATEPART(Year, [t18].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t18].[value]))))))) AND ([t18].[value] >= @p5) AND ([t18].[value] < @p6) AND (((
SELECT [t20].[OrderLifeCycleId]
FROM (
SELECT TOP (1) [t19].[OrderLifeCycleId]
FROM [dbo].[OrderOrderLifeCycle] AS [t19]
WHERE [t19].[OrderId] = [t18].[Id]
ORDER BY [t19].[Id] DESC
) AS [t20]
)) IN (@p7, @p8, @p9)) AND (EXISTS(
SELECT NULL AS [EMPTY]
FROM [dbo].[OrderOrderPaymentStatus] AS [t21]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t22] ON [t22].[Id] = [t21].[OrderPaymentStatusId]
WHERE ([t22].[Code] IN (@p10, @p11, @p12)) AND ([t21].[OrderId] = [t18].[Id])
))
) AS [t23]
)))) + @p14) + (
(CASE
WHEN (CONVERT(Int,DATALENGTH(CONVERT(NVarChar,DATEPART(Month, (
SELECT [t63].[value]
FROM (
SELECT TOP (1) [t58].[value]
FROM (
SELECT (
SELECT [t57].[DateTime]
FROM (
SELECT TOP (1) [t55].[DateTime]
FROM [dbo].[OrderOrderPaymentStatus] AS [t55]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t56] ON [t56].[Id] = [t55].[OrderPaymentStatusId]
WHERE ([t56].[Code] IN (@p0, @p1, @p2)) AND ([t55].[OrderId] = [t54].[Id])
) AS [t57]
) AS [value], [t54].[Id]
FROM [dbo].[Order] AS [t54]
) AS [t58]
WHERE ((([t13].[value4] IS NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NULL)) OR (([t13].[value4] IS NOT NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NOT NULL) AND ([t13].[value4] = (((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value]))))))) AND ([t58].[value] >= @p5) AND ([t58].[value] < @p6) AND (((
SELECT [t60].[OrderLifeCycleId]
FROM (
SELECT TOP (1) [t59].[OrderLifeCycleId]
FROM [dbo].[OrderOrderLifeCycle] AS [t59]
WHERE [t59].[OrderId] = [t58].[Id]
ORDER BY [t59].[Id] DESC
) AS [t60]
)) IN (@p7, @p8, @p9)) AND (EXISTS(
SELECT NULL AS [EMPTY]
FROM [dbo].[OrderOrderPaymentStatus] AS [t61]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t62] ON [t62].[Id] = [t61].[OrderPaymentStatusId]
WHERE ([t62].[Code] IN (@p10, @p11, @p12)) AND ([t61].[OrderId] = [t58].[Id])
))
) AS [t63]
)))) / 2)) >= @p15 THEN CONVERT(NVarChar,DATEPART(Month, (
SELECT [t63].[value]
FROM (
SELECT TOP (1) [t58].[value]
FROM (
SELECT (
SELECT [t57].[DateTime]
FROM (
SELECT TOP (1) [t55].[DateTime]
FROM [dbo].[OrderOrderPaymentStatus] AS [t55]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t56] ON [t56].[Id] = [t55].[OrderPaymentStatusId]
WHERE ([t56].[Code] IN (@p0, @p1, @p2)) AND ([t55].[OrderId] = [t54].[Id])
) AS [t57]
) AS [value], [t54].[Id]
FROM [dbo].[Order] AS [t54]
) AS [t58]
WHERE ((([t13].[value4] IS NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NULL)) OR (([t13].[value4] IS NOT NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NOT NULL) AND ([t13].[value4] = (((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value]))))))) AND ([t58].[value] >= @p5) AND ([t58].[value] < @p6) AND (((
SELECT [t60].[OrderLifeCycleId]
FROM (
SELECT TOP (1) [t59].[OrderLifeCycleId]
FROM [dbo].[OrderOrderLifeCycle] AS [t59]
WHERE [t59].[OrderId] = [t58].[Id]
ORDER BY [t59].[Id] DESC
) AS [t60]
)) IN (@p7, @p8, @p9)) AND (EXISTS(
SELECT NULL AS [EMPTY]
FROM [dbo].[OrderOrderPaymentStatus] AS [t61]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t62] ON [t62].[Id] = [t61].[OrderPaymentStatusId]
WHERE ([t62].[Code] IN (@p10, @p11, @p12)) AND ([t61].[OrderId] = [t58].[Id])
))
) AS [t63]
)))
ELSE REPLICATE(@p16, @p15 - (CONVERT(Int,DATALENGTH(CONVERT(NVarChar,DATEPART(Month, (
SELECT [t63].[value]
FROM (
SELECT TOP (1) [t58].[value]
FROM (
SELECT (
SELECT [t57].[DateTime]
FROM (
SELECT TOP (1) [t55].[DateTime]
FROM [dbo].[OrderOrderPaymentStatus] AS [t55]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t56] ON [t56].[Id] = [t55].[OrderPaymentStatusId]
WHERE ([t56].[Code] IN (@p0, @p1, @p2)) AND ([t55].[OrderId] = [t54].[Id])
) AS [t57]
) AS [value], [t54].[Id]
FROM [dbo].[Order] AS [t54]
) AS [t58]
WHERE ((([t13].[value4] IS NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NULL)) OR (([t13].[value4] IS NOT NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NOT NULL) AND ([t13].[value4] = (((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value]))))))) AND ([t58].[value] >= @p5) AND ([t58].[value] < @p6) AND (((
SELECT [t60].[OrderLifeCycleId]
FROM (
SELECT TOP (1) [t59].[OrderLifeCycleId]
FROM [dbo].[OrderOrderLifeCycle] AS [t59]
WHERE [t59].[OrderId] = [t58].[Id]
ORDER BY [t59].[Id] DESC
) AS [t60]
)) IN (@p7, @p8, @p9)) AND (EXISTS(
SELECT NULL AS [EMPTY]
FROM [dbo].[OrderOrderPaymentStatus] AS [t61]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t62] ON [t62].[Id] = [t61].[OrderPaymentStatusId]
WHERE ([t62].[Code] IN (@p10, @p11, @p12)) AND ([t61].[OrderId] = [t58].[Id])
))
) AS [t63]
)))) / 2))) + (CONVERT(NVarChar,DATEPART(Month, (
SELECT [t63].[value]
FROM (
SELECT TOP (1) [t58].[value]
FROM (
SELECT (
SELECT [t57].[DateTime]
FROM (
SELECT TOP (1) [t55].[DateTime]
FROM [dbo].[OrderOrderPaymentStatus] AS [t55]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t56] ON [t56].[Id] = [t55].[OrderPaymentStatusId]
WHERE ([t56].[Code] IN (@p0, @p1, @p2)) AND ([t55].[OrderId] = [t54].[Id])
) AS [t57]
) AS [value], [t54].[Id]
FROM [dbo].[Order] AS [t54]
) AS [t58]
WHERE ((([t13].[value4] IS NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NULL)) OR (([t13].[value4] IS NOT NULL) AND ((((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value])))) IS NOT NULL) AND ([t13].[value4] = (((CONVERT(NVarChar,DATEPART(Year, [t58].[value]))) + @p13) + (CONVERT(NVarChar,DATEPART(Month, [t58].[value]))))))) AND ([t58].[value] >= @p5) AND ([t58].[value] < @p6) AND (((
SELECT [t60].[OrderLifeCycleId]
FROM (
SELECT TOP (1) [t59].[OrderLifeCycleId]
FROM [dbo].[OrderOrderLifeCycle] AS [t59]
WHERE [t59].[OrderId] = [t58].[Id]
ORDER BY [t59].[Id] DESC
) AS [t60]
)) IN (@p7, @p8, @p9)) AND (EXISTS(
SELECT NULL AS [EMPTY]
FROM [dbo].[OrderOrderPaymentStatus] AS [t61]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t62] ON [t62].[Id] = [t61].[OrderPaymentStatusId]
WHERE ([t62].[Code] IN (@p10, @p11, @p12)) AND ([t61].[OrderId] = [t58].[Id])
))
) AS [t63]
))))
END)) AS [value], [t13].[value] AS [value2], [t13].[value2] AS [value22], [t13].[value3]
FROM (
SELECT SUM([t8].[value3]) AS [value], SUM([t8].[TotalAmount]) AS [value2], SUM([t8].[value22]) AS [value3], [t8].[value] AS [value4]
FROM (
SELECT ((CONVERT(NVarChar,DATEPART(Year, [t7].[value]))) + @p4) + (CONVERT(NVarChar,DATEPART(Month, [t7].[value]))) AS [value], [t7].[value] AS [value2], [t7].[Id], [t7].[value3], [t7].[TotalAmount], [t7].[value2] AS [value22]
FROM (
SELECT (
SELECT [t3].[DateTime]
FROM (
SELECT TOP (1) [t1].[DateTime]
FROM [dbo].[OrderOrderPaymentStatus] AS [t1]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t2] ON [t2].[Id] = [t1].[OrderPaymentStatusId]
WHERE ([t2].[Code] IN (@p0, @p1, @p2)) AND ([t1].[OrderId] = [t0].[Id])
) AS [t3]
) AS [value], [t0].[TotalAmount], (
SELECT SUM([t5].[value])
FROM (
SELECT COALESCE([t4].[BTWAmount],@p3) AS [value], [t4].[OrderId]
FROM [dbo].[OrderItem] AS [t4]
) AS [t5]
WHERE [t5].[OrderId] = [t0].[Id]
) AS [value2], (
SELECT COUNT(*)
FROM [dbo].[OrderItem] AS [t6]
WHERE [t6].[OrderId] = [t0].[Id]
) AS [value3], [t0].[Id]
FROM [dbo].[Order] AS [t0]
) AS [t7]
) AS [t8]
WHERE ([t8].[value2] >= @p5) AND ([t8].[value2] < @p6) AND (((
SELECT [t10].[OrderLifeCycleId]
FROM (
SELECT TOP (1) [t9].[OrderLifeCycleId]
FROM [dbo].[OrderOrderLifeCycle] AS [t9]
WHERE [t9].[OrderId] = [t8].[Id]
ORDER BY [t9].[Id] DESC
) AS [t10]
)) IN (@p7, @p8, @p9)) AND (EXISTS(
SELECT NULL AS [EMPTY]
FROM [dbo].[OrderOrderPaymentStatus] AS [t11]
INNER JOIN [dbo].[OrderPaymentStatus] AS [t12] ON [t12].[Id] = [t11].[OrderPaymentStatusId]
WHERE ([t12].[Code] IN (@p10, @p11, @p12)) AND ([t11].[OrderId] = [t8].[Id])
))
GROUP BY [t8].[value]
) AS [t13]
) AS [t64]
ORDER BY [t64].[value]
这适用于iPhone 5c(iOS 9.3.1),iPad(iOS 9.3.2)但不适用于iPhone 4s(iOS 9.3.2)。任何人都可以说出错了吗?