ALTER PROCEDURE dbo.Articles_InsertA开发者_开发技巧rticle
@Article nvarchar(MAX),
@UsersID uniqueidentifier
AS
INSERT INTO Articles
(UsersID,Article,PageNumber)
SELECT @UsersID,
@Article,
floor(COUNT(ArticleID)/5)
FROM Articles
I am not sure if the syntax correct..But what I want is to pass the query 2 parameters: Article and UserID..insert both, then insert the page number..Basically get the count of the article ID and divide by 5... I cant get an awkward number. I also want the Number to be a whole number.. (so not 1/5 but 0..not 9/5 , but 1)
UPDATED ABOVE..
It tells me to declare UsersID..syntax error
INSERT INTO Articles (UsersID,Article,PageNumber)
VALUES (@UsersID, @Article, ROUND(SELECT COUNT(ArticleID)/5 FROM Articles),0)
I'm not following where PageNumber comes from. But at the very least, the structure of your insert statement is incorrect and should look like this:
insert into Articles(UsersID, Article, PageNumber)
select @UsersID, @Article, count(*) / 5
FROM Articles
WHERE Article = @Article
I took a guess at what you're looking for with the PageNumber, but we'll likely need more information.
精彩评论