May 3, 2006 at 9:56 am
Hi,
I have a table of Reviews carried out on an item. The structure of the table is:
ReviewID int NOT NULL IDENTITY (1, 1),
ItemID int NOT NULL,
ReviewType varchar(50) NOT NULL,
ReviewBy varchar(8) NOT NULL,
ReviewDate datetime NOT NULL,
Active bit NOT NULL,
LastModified datetime NOT NULL
My Function is to return the last Reviewer (ReviewBy) given an ItemID. Here's what I've tried but it won't save:
CREATE FUNCTION dbo.LastReviewed
(
@ItemID int
)
RETURNS varchar(8)
AS
BEGIN
Declare @RetVal varchar(8)
SELECT @RetVal =
(SELECT ReviewBy
FROM dbo.review
WHERE ItemID = @ItemID
ORDER BY ReviewID DESC)
RETURN @RetVal
END
I'm creating this through VS and don't have Enterprise Manager so error message is fairly scant (Operation Cannot Be Completed)
What have i done wrong?
Thanks.
May 3, 2006 at 10:03 am
SELECT @RetVal = ReviewBy
FROM dbo.review
WHERE ItemID = @ItemID
ORDER BY ReviewBy DESC
May 3, 2006 at 10:09 am
Spot on! Thanks.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply