【发布时间】:2018-02-27 15:56:23
【问题描述】:
我在使用 SQL 'as' 语句时遇到了困难。根据我在 YouTube 上阅读和看到的内容,'as' 或 alias 命令可用于重命名列。
错误:
System.Exception:无效的对象名称“Capprogram”
选择 main1.id 作为 captempCaseMgmtMain_id , CapSSMatrix.Name 作为 captempCaseMgmtMain_idSSMatrix , CapSSMatrix.datefrom 作为 Date , CapSSMatrix.dateto 作为 DateTo , Person.lastname +' , '+Person.firstname 作为 Name , main1.date 作为 captempCaseMgmtMain_id , Capprogram.program 作为 captempCaseMgmtMain_idProgram从 captempCaseMgmtMain main1 左加入 captempCaseMgmtMain main2 on main2.ssmgroup = main1.ssmgroup 和 main2.type = 3 在 main1.idSSMatrix = CapSSMatrix.id 上加入 CapSSMatrix 在 Person.id = main1.familymember 上加入 Capprogram 在 capprogram.id = main1 上。 idprogram where main1.type = 1 and isumeric(main2.id) 1 and ((getdate() > capSSMatrix.dateto) ) and CapSSMatrix.id = '' order by main1.id desc at IMSE.UI.BaseEnginePage.GetDBValues () 在 IMSE.UI.Pages.Aspx_Pages.LoadPage() 在 IMSE.UI.Pages.Aspx_Pages.Page_Load(Object sender, EventArgs e)
这是我尝试过的命令/查询。任何帮助表示赞赏。提前谢谢你。
SELECT
main1.id AS captempCaseMgmtMain_id,
CapSSMatrix.Name AS captempCaseMgmtMain_idSSMatrix,
CapSSMatrix.datefrom AS Date,
CapSSMatrix.dateto AS DateTo,
Person.lastname + ', ' + Person.firstname AS Name,
main1.date AS captempCaseMgmtMain_id,
Capprogram.program AS captempCaseMgmtMain_idProgram
FROM
captempCaseMgmtMain main1
LEFT JOIN
captempCaseMgmtMain main2 ON main2.ssmgroup = main1.ssmgroup
AND main2.type = 3
JOIN
CapSSMatrix ON main1.idSSMatrix = CapSSMatrix.id
JOIN
Person ON Person.id = main1.familymember
JOIN
Capprogram ON capprogram.id = main1.idprogram
WHERE
main1.type = 1 AND
ISNUMERIC(main2.id) <> 1 AND
(GETDATE() > capSSMatrix.dateto) AND
CapSSMatrix.id = $CapSSMatrix.id
ORDER BY
main1.id DESC
【问题讨论】:
-
我怀疑这与别名有关。我认为这是因为您没有名为
Capprogram的表或视图。也许它只有一个 p。 -
如果您的查询与表所在的架构不同,则需要使用架构名称对其进行限定。始终使用模式名称对其进行限定是一个好习惯。
标签: sql sql-server