0

我有一个这样的存储过程:

alter procedure [dbo].[carcallvalidation]
@carid nvarchar(100)=null
as
begin
    select count(t.TBarcode) as barcodeCount, t.Paid,t.Status,t.DelDate
    from Transaction_tbl t
    where TBarcode=@carid

    group by t.paid,t.status,t.DelDate

    declare @transid integer=null;
   select @transid= t1.transactID from Transaction_tbl t1 where TBarcode=@carid;
if(select count(k.transactid) from KHanger_tbl k where k.transactid=@transid)>0
begin
return 1
end
end

如果我传递carid了错误的数字,则返回一个空表;但我希望它改为T.Barcode计数为 0。

我怎样才能做到这一点?

4

2 回答 2

0

you have to remove filter in from where condition then .

Try following store procedure:

ALTER procedure [dbo].[carcallvalidation111]
@carid nvarchar(100)=null
as
begin
select count(case when t.TBarcode is null or t.TBarcode!=@carid then 0 else 1 end) as cnt,  t.Paid,t.Status,t.DelDate
from Transaction_tbl t
group by t.Paid,t.Status,t.DelDate;

declare @transid integer=null;

select @transid= t1.transactID from Transaction_tbl t1 where TBarcode=@carid;
if(select count(k.transactid) from KHanger_tbl k where k.transactid=@transid)>0
begin
return 1
end
end
于 2013-06-30T06:57:57.193 回答
0

我建议你试试这个。

    alter procedure [dbo].[carcallvalidation]
    @carid nvarchar(100)=null,
@countTbar int 
    as
    begin
        select @countTbar=  select count(t.TBarcode) as barcodeCount
        from Transaction_tbl t
        where TBarcode=@carid  group by t.paid,t.status,t.DelDate
 if(@countTbar is null)
    begin
    return 0
    end

        select count(t.TBarcode) as barcodeCount, t.Paid,t.Status,t.DelDate
        from Transaction_tbl t
        where TBarcode=@carid

        group by t.paid,t.status,t.DelDate

        declare @transid integer=null;
       select @transid= t1.transactID from Transaction_tbl t1 where TBarcode=@carid;
    if(select count(k.transactid) from KHanger_tbl k where k.transactid=@transid)>0
    begin
    return 1
    end
    end
于 2013-06-30T07:04:48.873 回答