我确信我必须在这里犯一个微不足道的错误,但我一直在寻找这个问题的帮助,我所能找到的只是条件INNER JOIN的信息。
<编辑> 问题是这个存储过程根本没有返回任何内容。如果我输入:
SELECT TOP (6) UserID, Category, Title, SUBSTRING(Article, 0, 200) AS Summary, DatePosted
FROM ContribContent
WHERE (DateFeatured IS NOT NULL)
ORDER BY DateFeatured DESC
进入控制台然后我得到返回的值。那么它必须与内部联接有关吗?的< /编辑>
这个想法是:
以下是代码:
ALTER PROCEDURE [dbo].[admin_GetFeaturedContrib]
AS
BEGIN
DECLARE @FeaturedContrib TABLE (
UserID INT,
Category INT,
Title varchar(100),
Summary varchar(200),
DatePosted date,
FirstName varchar(50),
LastName varchar(50),
Picture varchar(100)
)
INSERT INTO @FeaturedContrib
SELECT TOP 6 ContribContent.UserID, ContribContent.Category, ContribContent.Title, SUBSTRING(ContribContent.Article, 0, 200) AS Summary, ContribContent.DatePosted, Users.FirstName, Users.LastName, Users.Picture
FROM ContribContent
INNER JOIN Users
ON ContribContent.UserID = Users.UserID
WHERE ContribContent.DateFeatured IS NOT NULL
ORDER BY ContribContent.DateFeatured DESC
SELECT * FROM @FeaturedContrib
END
涉及两个数据表:
用户 - 存储所有用户及其信息的表格。
ContribContent
感谢给任何可以提供帮助的人!
答案 0 :(得分:2)
仅限运行 -
SELECT TOP 6 ContribContent.UserID, ContribContent.Category, ContribContent.Title, SUBSTRING(ContribContent.Article, 0, 200) AS Summary, ContribContent.DatePosted, Users.FirstName, Users.LastName, Users.Picture
FROM ContribContent
INNER JOIN Users
ON ContribContent.UserID = Users.UserID
WHERE ContribContent.DateFeatured IS NOT NULL
ORDER BY ContribContent.DateFeatured DESC
如果您首先返回任何数据,请查看您的Where
或join
可能导致的问题。我的猜测是join
看看你是否有匹配的用户ID ...(提示:左连接可能是你的回答)