0

我有这样的存储过程:

ALTER procedure [dbo].[carcallvalidation]
@carid nvarchar(100)=null
as
begin
    select count(*)t.TBarcode, t.Paid,t.Status,t.DelDate
    from Transaction_tbl t
    where TBarcode=@carid;
    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

我想在执行如下错误时计算 T.TBarcode:'.' 附近的语法不正确。

4

3 回答 3

0

尝试以下存储过程:

ALTER procedure [dbo].[carcallvalidation] @carid nvarchar(100)=null
as
begin

    select sum(case when t.TBarcode is null then 0 else 1 end) as cnt, 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-30T06:17:44.273 回答
0

从 Transaction_tbl t 中选择count(*)t.TBarcode, t.Paid,t.Status,t.DelDate 。粗体陈述是您回答不正确的地方。这是不可能的count(*)t.TBarcode

在 where 条件之后添加以下内容

group by t.Paid,t.Status,t.DelDate;

如果您想要总和,t.paid请不要将其放在group by子句中。

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

    group by 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:19:35.797 回答
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
于 2013-06-30T06:24:14.940 回答