0

ストアドプロシージャを作成していますが、コンパイラがエラー仕様をまったく表示しないので、何が問題なのか理解できません。クエリがエラーで完了したと言っているだけです。エラーがわかりません..?!

これは、2つのテーブルを更新するストアドプロシージャとして使用されます。コード自体はかなり自明です。

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[insertRankingData]
@domannamn [varchar](100),
@keyword [varchar](100),
@dagensdatum [Date],
@rankingposition [Decimal]
AS
DECLARE @domanID int 
DECLARE @datumen date 

IF(SELECT COUNT(*) FROM [dbo].[t_doman] WHERE doman_namn = @domannamn) = 0
BEGIN
INSERT INTO [dbo].[t_doman] (doman_namn) 
    VALUES(@domannamn)

    SELECT @domanID = SCOPE_IDENTITY()
SELECT @todaysdate = GETDATE()
END
ELSE
BEGIN
SELECT @domanID = [doman_id] 
    FROM [dbo].[t_doman] 
    WHERE doman_namn = @domannamn

SELECT @todaysdate = GETDATE()
END

IF NOT @domanID IS NULL
BEGIN 
IF NOT EXISTS (SELECT (ranking_date, ranking_keyword, ranking_id_doman) 
                    FROM [dbo].[t_ranking] 
                    WHERE ranking_id_doman = @domanID
                    AND ranking_keyword = @keyword
                    AND ranking_date = @datumen)
BEGIN

       INSERT INTO [dbo].[t_ranking] (ranking_id_doman, ranking_date, ranking_position, ranking_keyword) 
       VALUES(@domanID, @todaysdate, @rankingposition, @keyword)    
END
ELSE
BEGIN 
       UPDATE [dbo].[t_ranking] 
       SET ranking_position = @rankingposition
       WHERE ranking_date = @todaysdate
       AND ranking_keyword = @keyword
       AND ranking_id_doman = @domanID 
END
  END
4

1 に答える 1

1

これを試して:

ALTER PROCEDURE [dbo].[insertRankingData]
@domannamn [varchar](100),
@keyword [varchar](100),
@dagensdatum [Date],
@rankingposition [Decimal]
AS
DECLARE @domanID int 
DECLARE @datumen date 
IF EXISTS(SELECT 1 FROM [dbo].[t_doman] WHERE doman_namn = @domannamn)
BEGIN
INSERT INTO [dbo].[t_doman] (doman_namn) VALUES(@domannamn)
SELECT @domanID = SCOPE_IDENTITY()
SELECT @todaysdate = GETDATE()
END
ELSE
BEGIN
SELECT @domanID = [doman_id] FROM [dbo].[t_doman] WHERE doman_namn = @domannamn
SELECT @todaysdate = GETDATE()
END
IF @domanID IS NOT NULL
BEGIN 
IF NOT EXISTS (SELECT ranking_date, ranking_keyword, ranking_id_doman
                    FROM [dbo].[t_ranking] 
                    WHERE ranking_id_doman = @domanID
                    AND ranking_keyword = @keyword
                    AND ranking_date = @datumen)
BEGIN
INSERT INTO [dbo].[t_ranking] (ranking_id_doman, ranking_date, ranking_position, ranking_keyword) 
    VALUES(@domanID, @todaysdate, @rankingposition, @keyword)   
END
ELSE
BEGIN 
    UPDATE [dbo].[t_ranking] 
    SET ranking_position = @rankingposition
    WHERE ranking_date = @todaysdate
    AND ranking_keyword = @keyword
    AND ranking_id_doman = @domanID 
END
  END

お役に立てれば!!

于 2012-11-01T19:38:29.107 に答える