select
tr.TransactionId as TxnIdentifier,
m.MerchantName as MerchantName,
case
when tr.ChannelType=2 then 'ACH'
when tr.ChannelType=3 then 'CC'
when tr.ChannelType=4 then 'Debit'
else null
end as ChannelType,
tr.CaptureAmount as CaptureAmount,
case when tr.OperationType=0 then 'Sale'
when tr.OperationType=1 then 'Verify only'
when tr.OperationType=2 then 'ForceSale'
when tr.OperationType=3 then 'Adjust'
when tr.OperationType=4 then 'Activate'
when tr.OperationType=5 then 'Deactivate'
when tr.OperationType=6 then 'Reload'
when tr.OperationType=7 then 'Refund'
when tr.OperationType=8 then 'Inquire'
else null end as TxnType,
case when tr.TransactionStatus=0 then 'Created'
when tr.TransactionStatus=1 then 'Pending'
when tr.TransactionStatus=2 then 'Authorized'
when tr.TransactionStatus=3 then 'Posted'
when tr.TransactionStatus=4 then 'Accepted'
when tr.TransactionStatus=5 then 'Failed'
when tr.TransactionStatus=6 then 'Returned'
when tr.TransactionStatus=7 then 'Chargeback'
when tr.TransactionStatus=8 then 'Void'
when tr.TransactionStatus=9 then 'Refunded'
when tr.TransactionStatus=10 then 'Approved'
when tr.TransactionStatus=11 then 'Void attempted'
when tr.TransactionStatus=12 then 'Refund attempted'
when tr.TransactionStatus=13 then 'Hold'
when tr.TransactionStatus=14 then 'Denied'
when tr.TransactionStatus=15 then 'Settlement hold'
when tr.TransactionStatus=16 then 'Success'
when tr.TransactionStatus=17 then 'Retried'
when tr.TransactionStatus=100 then 'Unknown'
else null end as TxnStatus,
tr.PreAuthCode as AuthCode,
DATE_FORMAT(tr.TransactionDate, '%m-%d-%Y %H:%i:%s') as TransactionDate,
case when tr.OperationType='7' then tr.Amount
else null end as RefundAmount,
case when tr.OperationType='7'
then DATE_FORMAT(tr.TransactionDate, '%m-%d-%Y %H:%i:%s')
else null end as RefundedOn,
tr.TraceNumber as TraceNumber
from TransactionEntity tr
inner join `enter code here`DOMAIN.Merchant m on m.Id=tr.MerchantId where 1=1
and (tr.MerchantId = merchantId or merchantId=0)
and (tr.ChannelType = channelType or channelType=0)
And (tr.TransactionDate >= startDate or startDate is null)
And (tr.TransactionDate <= endDate or endDate is null)
ORDER BY
CASE WHEN sortField = 'TransactionDate' AND sortDirection='ASC' THEN TransactionDate END ASC,
CASE WHEN sortField = 'TransactionDate' AND sortDirection='DESC' THEN TransactionDate END DESC
如果在存储过程外部应用order by子句,它可以正常工作,但在sp内部它不工作(在transactiondate上应用order by desc不工作)
2条答案
按热度按时间44u64gxh1#
尝试创建如下所示的存储过程
wqlqzqxt2#
你不能在一个订单上使用两种排序方式。