SQL Server using AND with IF? -
I am writing a stored procedure, but I can not understand what the compiler is wrong all about. Simply say that the complete query with errors. I can not see the error ..?!
This is used as a stored procedure that updates two tables, the code itself is very clear.
Set the GO ALTER process [dbo] at SET ANSI_NULLS at QUOTED_IDENTIFIER. [InsertRankingData] Select @domannamn [varchar] (100), @keyword [varchar] (100), @dagensdatum [date], @rankingposition [decimal] declared @datumen on IF as announced @domanID integer (COUNT (*) [Dbo]. [T_doman] ou doman_namn = @domannamn) = 0 [dbo] begin to insert. [T_doman] (doman_namn) Select values (@domannamn) Select @domanID = select SCOPE_IDENTITY () @todaysdate = GETDATE () end and the beginning of @domanID = [doman_id] [dbo]. [T_doman] Where doman_namn = @domannamn choose @todaysdate = GETDATE () do not end @domanID does not exist zero start (select (ranking_date, ranking_keyword, ranking_id_doman) [dbo] from. [T_ranking] Where ranking_id_doman = @domanID and ranking_keyword = @keyword and ranking_date = @datumen) [dbo]. [T_ranking] (ranking_id_doman, Ranking_date, ranking_position, ranking_keyword) values (@domanID, @todaysdate, @rankingposition, @keyword) end and startup updates [dbo]. [T_ranking] set ranking_position = @rankingposition where ranking_date = @todaysdate and ranking_keyword = @keyword and ranking_id_doman = @domanID END END
Try this:
ALTER process [dbo]. [InsertRankingData] @domannamn [varchar] (100), @keyword [varchar] (100), @dagensdatum [date], @rankingposition [decimal] Announcement of @domanID integer exists as @datumen date ([dbo] Selection from 1. [t_doman] ou doman_namn = @domannamn) [dbo] start putting in. [T_doman] (doman_namn) start values end (@domannamn) Select @domanID = SCOPE_IDENTITY (Select @todaysdate = GETDATE ()) or @domanID = [doman_id] [dbo]. From [t_doman] Where doman_namn = @domannamn selection @todaysdate = GETDATE () end @domanID do not start NULL, if not present, select (selection ranking_date, ranking_keyword, ranking_i [dbo] to d_doman. [T_ranking] Where ranking_id_doman = @ Domanid and ranking_keyword = @keyword and ranking_date = @datumen) [dbo]. [T_Ranking] (Rank_id_doman, ranking_date, ranking_position, ranking_keyword) values (@domanID, @ today's date, @ ranking position, @keyword) Finally update [dbo]. [T_Ranking] STE Ranking Ranking_position = @RankingPosition where ranking_data = @todaysdate and ranking_keyword = @ keyword and ranking_id_omain = @domainand end Hope this helps !!
Comments
Post a Comment