我对使用存储过程有点陌生,所以我偶然发现了两个问题。
首先,为什么我不允许这样做?错误信息说:
操作数类型冲突:日期与 int 不兼容
代码 :
@time date OUTPUT
SELECT @time = ranking_date
FROM [dbo].[t_ranking]
WHERE ranking_date <= DATEDIFF(day, @todaysDateminusthirty, @todaysdate)
AND ranking_keyword = @keyword
AND ranking_id_doman = @domainID
以后如何将结果作为完整数据集返回?而不是保存到两个变量中?或者他们可以容纳不止一排?
ALTER PROCEDURE [dbo].[fetchRankingData]
-- Add the parameters for the stored procedure here
@domannamn [varchar](100),
@keyword [varchar](100),
@rankingen [decimal](6,2) OUTPUT,
@time date OUTPUT
AS
DECLARE @domainID int
DECLARE @todaysDateminusthirty datetime
DECLARE @todaysdate datetime
BEGIN
SET NOCOUNT ON;
IF EXISTS(SELECT 1 FROM [dbo].[t_doman] WHERE doman_namn = @domannamn)
BEGIN
set @todaysdate = getdate()
set @todaysDateminusthirty = DATEADD(day,-30,@todaysdate)
SELECT @domainID = doman_id FROM [dbo].[t_doman] WHERE doman_namn = @domannamn
IF EXISTS(SELECT 1 FROM [dbo].[t_ranking] WHERE ranking_id_doman = @domainID AND ranking_keyword = @keyword)
BEGIN
SELECT @rankingen = ranking_position FROM
[dbo].[t_ranking] WHERE ranking_keyword = @keyword
AND ranking_id_doman = @domainID
SELECT @time = ranking_date FROM
[dbo].[t_ranking] WHERE ranking_date <= DATEDIFF(day,@todaysDateminusthirty,@todaysdate) AND ranking_keyword = @keyword
AND ranking_id_doman = @domainID
END
END
END