我有这样的存储过程:
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的数量 执行错误时会出现这样的错误:'。'。
附近的语法不正确答案 0 :(得分: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
答案 1 :(得分:0)
选择 count(*)t.TBarcode
,t.Paid,t.Status,t.DelDate
来自Transaction_tbl t。粗体陈述是您回答的地方不正确的地方。这不可能是count(*)t.TBarcode
。
在条件
之后添加以下内容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
答案 2 :(得分: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