我有这样的搜索数据查询:
select top 100 * from Payment
where PayId is not null and
PayAccount like '%10158002%'and
PayCustName like '%XXXX XXXXX%'and
PayAmount like '%429000%'and
PayAmountPaid like '%429000%'and
PayResponse like '%00%'and
PayRefNo like '%101306000013%'and
cast(PayDatetime as date) = ( select convert(date , '03/06/2013', 103))
order by PayDatetime DESC
并给我这样的结果:
PayId PayAccount PayCustName PayAmount PayAmountPaid PayResponse PayRefNo PayScreenText PayReceiptText PayDatetime PayBankCode
49 10158002 XXXX XXXXX 429000 429000 00 101306000013 xxx xxx 2013-06-03 11:43:18.210 112
我必须这样做才能通过与其他表进行内部连接来生成PayResponse 00
文本:success
select para.Value2
from Payment pay
inner join
Parameter para
on pay.PayResponse = para.Value1
我应该通过使用另一个内部连接来检查 refno 是否被另一个表使用,但它使用了一个存储过程:
ALTER PROCEDURE [dbo].[Rintis_StatusReversal]
@RefNoPay as varchar (20),
@Count as int output,
@Response as int output,
@Text as varchar(20) output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Select @Count = COUNT(*)
from
payment Pay
inner join
Reversal Rev
on Pay.PayRefNo = Rev.PayRefNo
where Pay.PayRefNo = @RefNoPay
if @Count > 0
Begin
SET @Response = 1
SET @Text = 'Reversed'
End
Else
Begin
SET @Response = 0
SET @Text = 'Paid'
End
select @Response , @Text
END
通过执行我想获得 @text 值的过程,它是success
or reversed
。我想将值输入到第一个查询结果。
所以我想得到的查询是这样的:
PayId PayAccount PayCustName PayAmount PayAmountPaid PayResponse PayRefNo PayScreenText PayReceiptText PayDatetime PayBankCode RefStatus
49 10158002 XXXX XXXXX 429000 429000 00 101306000013 xxx xxx 2013-06-03 11:43:18.210 112 Success
可以这样做吗?我仍然对复杂的 sql 查询感到困惑。谢谢你的帮助