This trigger works perfectly. Unfortunately, I need it to do more, I THINK , I need it to delete the previous insert that this trigger performed first before it inserts the new values.
Here the whole thing.
I have a table called blog_blog, it has the following trigger on it.
I then have a tabled called blog_cat, Which is a topics table. It hold the current topics for my site. It has 2 columns, cat_no, cat_name.
cat_name | cat_no
Photos 1
Videos 2
Random 3
I then run the query below.
To show me the topics and if thier has been any blogs posted in the last 24 hours, If yes a 'New' shows up in column new, If not a null shows up, perfect.
This shows that their was a blog posted for photo and random in the last 24 hours, and nothing for video.
TOPICS
PHOTO*
VIDEO
RANDOM*
Problems comes when 2 blogs are posted in the last 24 hours I get the error below.
So I am under the impression that I should do a delete before I do the trigger insert, to keep just one record.
Here the whole thing.
I have a table called blog_blog, it has the following trigger on it.
Code:
CREATE TRIGGER bloglog
ON blog_blog
FOR INSERT
AS
DECLARE @find varchar(4)
select @find = inserted.blog_catagory from inserted
BEGIN
INSERT INTO blog_log
VALUES ('New',DATEADD (hh,+3,GETDATE()),'BLOG',@find);
END ;
GO
I then have a tabled called blog_cat, Which is a topics table. It hold the current topics for my site. It has 2 columns, cat_no, cat_name.
cat_name | cat_no
Photos 1
Videos 2
Random 3
I then run the query below.
Code:
Select cat_name, (Select log_status from blog_log where DATEDIFF ( hh ,log_date ,DATEADD(hh , +3, GetDate())) <= 24 and log_blogid = cat_no ) as 'new'
From blog_cat
This shows that their was a blog posted for photo and random in the last 24 hours, and nothing for video.
TOPICS
PHOTO*
VIDEO
RANDOM*
Problems comes when 2 blogs are posted in the last 24 hours I get the error below.
Code:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
So I am under the impression that I should do a delete before I do the trigger insert, to keep just one record.