-6

这是我的 SQL 语句:

 N.File_Id = ServerFiles.Id WHERE [...]

'File_Id' 以粉红色突出显示,无论如何我可以覆盖它吗?我认为这就是为什么我的 SQL 没有返回结果集的原因。

谢谢

修改后的代码:

SELECT 
   N.Id, NLoc.N_Id, Loc.Id as Loc_Id, 
   CAST(N.Text AS TEXT) as Text, FilePath, 
   CAST(N.Title AS TEXT) as Title, N.CreatD as RegDate
FROM 
   NLoc 
JOIN N ON NLoc.Not_Id = N.Id 
JOIN Loc ON NLoc.Loc_Id = Loc.Id
JOIN ServerFiles ON N.File_Id = ServerFiles.Id 
WHERE 
    Loc_Id IN (1)
4

2 回答 2

1

试试这个:

SELECT 
    N.Id
    , NLoc.N_Id
    , Loc.Id as Loc_Id
    , CAST(N.Text AS TEXT) as Text
    , FilePath
    , CAST(N.Title AS TEXT) as Title
    , N.CreatD as RegDate 

FROM NLoc 
     JOIN N  ON NLoc.Not_Id=N.Id 
     JOIN Loc ON NLoc.Loc_Id=Loc.Id 
     JOIN ServerFiles ON N.File_Id=ServerFiles.Id 
WHERE Loc.Id = 1

我看到的第一个问题是你不能使用在 WHERE 语句中的 SELECT 中定义的别名(所以你不能使用 Loc_Id,你必须使用 Loc.Id)。

让我知道这是否适合您,或者您仍然会收到错误消息。

我还注意到你使用 N.File_Id 和 N.Id,你确定你的表中有这两个列吗?您可以发布您的架构吗?

于 2012-08-31T11:59:53.357 回答
0

将其放在[ ]中,如[N].[File_Id]

SELECT 
N.Id, NLoc.N_Id, 
Loc.Id as Loc_Id, CAST(N.Text AS TEXT) as Text, 
FilePath, CAST(N.Title AS TEXT) as Title,
 N.CreatD as RegDate 

 FROM NLoc 
 JOIN N  ON NLoc.Not_Id=N.Id 
 JOIN Loc ON NLoc.Loc_Id=Loc.Id 
 JOIN ServerFiles ON [N].[File_Id]=ServerFiles.Id 
 WHERE NLoc.Loc_Id IN (1) -- or Loc.Id IN (1) 
于 2012-08-31T11:53:58.890 回答