我有以下SQL Server存储过程,当前端代码调用它时,它返回的返回值为0而不是总计数的选择。任何人都可以告诉我,我需要做些什么更改才能返回选择值而不是返回值
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[getTotalSent1]
(
@vendorworksationID uniqueidentifier ,
@sdate date,
@edate date
)
as
begin
select
camp.totalSent + bcamp.totalSent as totalSent
from
(select
COUNT(*) as totalSent
from
AdvertisedCampaignHistory a
where
CAST(a.CreationDate AS DATE) BETWEEN CAST(@sdate as DATE) AND CAST(@edate as DATE)
and a.CampaignID in (select cc.CampaignID
from campaign cc, VendorWorkStation vw
where cc.VendorWorkStationID = vw.VendorWorkStationID
and VendorID = @vendorworksationID)) as camp
join
(select
COUNT(*) as totalSent
from
AdvertisedCampaignHistory a
where
CAST(a.CreationDate AS DATE) BETWEEN CAST(@sdate as DATE) AND CAST(@edate as DATE)
and a.CampaignID in (select bc.BCampaignID
from BeaconCampaign bc, VendorWorkStation vw
where bc.VendorWorkStationID = vw.VendorWorkStationID
and VendorID = @vendorworksationID)) as bcamp on 1=1
end
输出:
Totalsent
---------
240
return
-----
0
它返回0,我想要总发送值
答案 0 :(得分:0)
CREATE PROCEDURE getTotalSent1
AS
DECLARE @TotalSent int
-- Do some work here
SELECT @TotalSent = 240
RETURN @TotalSent
GO
-- EXEC CODE
DECLARE @totalsent int
EXEC @totalsent = dbo.getTotalSent1
SELECT @totalsent as totalSent
答案 1 :(得分:0)
ALTER procedure [dbo].[getTotalSent1]
(
@vendorworksationID uniqueidentifier ,
@sdate date,
@edate date
@total_set int output
)
as
`enter code here`
return
像这样得到param
declare @got_it int
exec [dbo].[getTotalSent1] xxx,yyy,@total_set=@got_it output
`
答案 2 :(得分:0)
试试这个:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[getTotalSent1]
(
@vendorworksationID uniqueidentifier ,
@sdate date,
@edate date
)
as
begin
DECLARE @totalSent INT
select
@totalSent =camp.totalSent + bcamp.totalSent
from
(select
COUNT(*) as totalSent
from
AdvertisedCampaignHistory a
where
CAST(a.CreationDate AS DATE) BETWEEN CAST(@sdate as DATE) AND CAST(@edate as DATE)
and a.CampaignID in (select cc.CampaignID
from campaign cc, VendorWorkStation vw
where cc.VendorWorkStationID = vw.VendorWorkStationID
and VendorID = @vendorworksationID)) as camp
join
(select
COUNT(*) as totalSent
from
AdvertisedCampaignHistory a
where
CAST(a.CreationDate AS DATE) BETWEEN CAST(@sdate as DATE) AND CAST(@edate as DATE)
and a.CampaignID in (select bc.BCampaignID
from BeaconCampaign bc, VendorWorkStation vw
where bc.VendorWorkStationID = vw.VendorWorkStationID
and VendorID = @vendorworksationID)) as bcamp on 1=1
return @totalSent
end
答案 3 :(得分:0)
BEGIN
后SET NOCOUNT ON
;
这将禁用存储过程的默认返回值,以便您获得查询结果。
作为旁注,您需要用ANSI等效替换您的专有联接......
e.g。 ......
FROM tblA a
JOIN tblB b
ON a.key = b.key
最好避免在WHERE子句中进行连接。