ALTER PROCEDURE GetBookById
@BookId INT --传一个参数
AS
-- 最多放十个作者名
DECLARE @AuthorList nvarchar(480) SET NOCOUNT ON -- 初始化 @AuthorList
SELECT @AuthorList = "" -- 把作者的名字放到@AuthorList ,以,分割
SELECT @AuthorList = @AuthorList + a.Name + ", "
FROM Books b,
BookAuthor ba,
Authors a
WHERE b.ItemId = @BookId
AND ba.ItemId = b.ItemId
AND a.PKId = ba.AuthorId -- 去掉最后一个,
SELECT @AuthorList = LEFT(@AuthorList,LEN(@AuthorList) - 1) SELECT i.PKId,
i.TypeId,
b.PublisherId,
b.ISBN,
i.ImageFileSpec,
i.Name 'Title',
i.Description,
i.UnitPrice,
i.UnitCost,
t.Name 'ItemType',
p.Name 'PublisherName',
@AuthorList 'Authors'
FROM Items i,
Books b,
ItemCategory c,
ItemType t,
Publishers p
WHERE i.PKId = @BookId
AND c.ItemId = i.PKId
AND b.ItemId = i.PKId
AND p.PKId = b.PublisherId
AND t.PKId = i.TypeId
ORDER BY i.PKId RETURN 0
@BookId INT --传一个参数
AS
-- 最多放十个作者名
DECLARE @AuthorList nvarchar(480) SET NOCOUNT ON -- 初始化 @AuthorList
SELECT @AuthorList = "" -- 把作者的名字放到@AuthorList ,以,分割
SELECT @AuthorList = @AuthorList + a.Name + ", "
FROM Books b,
BookAuthor ba,
Authors a
WHERE b.ItemId = @BookId
AND ba.ItemId = b.ItemId
AND a.PKId = ba.AuthorId -- 去掉最后一个,
SELECT @AuthorList = LEFT(@AuthorList,LEN(@AuthorList) - 1) SELECT i.PKId,
i.TypeId,
b.PublisherId,
b.ISBN,
i.ImageFileSpec,
i.Name 'Title',
i.Description,
i.UnitPrice,
i.UnitCost,
t.Name 'ItemType',
p.Name 'PublisherName',
@AuthorList 'Authors'
FROM Items i,
Books b,
ItemCategory c,
ItemType t,
Publishers p
WHERE i.PKId = @BookId
AND c.ItemId = i.PKId
AND b.ItemId = i.PKId
AND p.PKId = b.PublisherId
AND t.PKId = i.TypeId
ORDER BY i.PKId RETURN 0
???????英文的注释我看的懂............. 分数不够可以在加................