Last active
August 29, 2015 14:13
-
-
Save HarryMcCarney/799ba800ee880cbb1efc to your computer and use it in GitHub Desktop.
auto assign sl proc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if exists ( select * | |
from sys.objects | |
where object_id = object_id('pub.auto_assign_storyline') | |
and type in ( 'p', 'pc' ) | |
) | |
drop proc pub.auto_assign_storyline | |
go | |
create proc pub.auto_assign_storyline | |
@blog_id int, | |
@url varchar(1024), | |
@title nvarchar(255), | |
@summary nvarchar (2000), | |
@picture_url varchar(1024), | |
@published datetime, | |
@topic_id int | |
as | |
begin | |
declare @article_id int | |
if not exists (select id from pub.article where url = @url) | |
begin | |
select 1 | |
insert pub.article | |
(guid, created, blog_id, status_id, url, title, summary, picture_url, updated, widget_picture_url, published, validated, three_day_impressions, seven_day_impressions) | |
select newid(), getutcdate(), @blog_id, 1, @url, @title, @summary, @picture_url, null, @picture_url, @published, 'OK', 0, 0; | |
set @article_id = scope_identity(); | |
end | |
else | |
begin | |
select 2 | |
select @article_id = id from pub.article where url = @url | |
end | |
if exists (select article_id from pub.article_topic where article_id = @article_id and [auto_assigned] = 0) | |
begin | |
select 3 | |
return | |
end | |
else | |
begin | |
select 4 | |
update pub.article_topic | |
set [topic_id] = @topic_id | |
where article_id = @article_id | |
if not exists(select article_id from pub.article_topic where article_id = @article_id) | |
insert [pub].[article_topic] | |
(article_id, topic_id, sort, created, auto_assigned) | |
select @article_id, @topic_id, 0, getutcdate(), 1 | |
end | |
end | |
go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment