无法绑定多部分标识符 'T1.[AcctName]'
The multi-part identifier 'T1.[AcctName]' could not be bound
我正在尝试从写入的查询中获取结果 below.from 我遇到了错误
The multi-part identifier "T1.AcctName" could not be bound.
我不知道为什么要这样。请帮忙。
SELECT T1.[AcctName],
SUM(T0.[DebLTotal]/85) AS buget
FROM OBGT T0
INNER JOIN
(
SELECT CASE WHEN T1.[AcctName] LIKE '%Salaries%' THEN 'Salaries'
WHEN T1.[AcctName] LIKE '%Travel%' THEN 'Travel'
WHEN T1.[AcctName] LIKE '%Supplies%' THEN 'Supplies'
WHEN T1.[AcctName] LIKE '%Consultants%' THEN 'Consultants'
WHEN T1.[AcctName] LIKE '%Patient%' THEN 'Patient Care'
WHEN T1.[AcctName] LIKE '%Equipment%' THEN 'Equipments'
WHEN T1.[AcctName] LIKE '%Expense%' THEN 'Other Expenses'
WHEN T1.[AcctName] LIKE '%Alteration%' THEN 'Alterations/Renovations'
ELSE 'Alterations/Renovations'
END as [AcctName],
[AcctCode]
from OACT
) as T1 ON T0.[AcctCode] = T1.[AcctCode]
INNER JOIN OBGS T2 ON T0.[Instance] = T2.[AbsId]
where T2.[Name] = 'Main Budget 2015'
GROUP BY T1.[AcctName]
您可以删除子查询中的别名:
SELECT T1.[AcctName],
SUM(T0.[DebLTotal]/85) AS buget
FROM OBGT T0
INNER JOIN
(
SELECT CASE WHEN [AcctName] LIKE '%Salaries%' THEN 'Salaries'
WHEN [AcctName] LIKE '%Travel%' THEN 'Travel'
WHEN [AcctName] LIKE '%Supplies%' THEN 'Supplies'
WHEN [AcctName] LIKE '%Consultants%' THEN 'Consultants'
WHEN [AcctName] LIKE '%Patient%' THEN 'Patient Care'
WHEN [AcctName] LIKE '%Equipment%' THEN 'Equipments'
WHEN [AcctName] LIKE '%Expense%' THEN 'Other Expenses'
WHEN [AcctName] LIKE '%Alteration%' THEN 'Alterations/Renovations'
ELSE 'Alterations/Renovations'
END as [AcctName],
[AcctCode]
from OAC
) AS T1
ON T0.[AcctCode] = T1.[AcctCode]
INNER JOIN OBGS T2 ON T0.[Instance] = T2.[AbsId]
where T2.[Name] = 'Main Budget 2015'
GROUP BY T1.[AcctName];
重点是别名 T1
在子查询外部定义,因此在内部不可见。
或者你可以在里面添加别名,比如:
SELECT T3.[AcctName],
SUM(T0.[DebLTotal]/85) AS buget
FROM OBGT T0
INNER JOIN
(
SELECT CASE WHEN T1.[AcctName] LIKE '%Salaries%' THEN 'Salaries'
WHEN T1.[AcctName] LIKE '%Travel%' THEN 'Travel'
WHEN T1.[AcctName] LIKE '%Supplies%' THEN 'Supplies'
WHEN T1.[AcctName] LIKE '%Consultants%' THEN 'Consultants'
WHEN T1.[AcctName] LIKE '%Patient%' THEN 'Patient Care'
WHEN T1.[AcctName] LIKE '%Equipment%' THEN 'Equipments'
WHEN T1.[AcctName] LIKE '%Expense%' THEN 'Other Expenses'
WHEN T1.[AcctName] LIKE '%Alteration%' THEN 'Alterations/Renovations'
ELSE 'Alterations/Renovations'
END as [AcctName],
[AcctCode]
from OACT AS T1
) as T3 ON T0.[AcctCode] = T3.[AcctCode]
INNER JOIN OBGS T2 ON T0.[Instance] = T2.[AbsId]
where T2.[Name] = 'Main Budget 2015'
GROUP BY T3.[AcctName]
我正在尝试从写入的查询中获取结果 below.from 我遇到了错误
The multi-part identifier "T1.AcctName" could not be bound.
我不知道为什么要这样。请帮忙。
SELECT T1.[AcctName],
SUM(T0.[DebLTotal]/85) AS buget
FROM OBGT T0
INNER JOIN
(
SELECT CASE WHEN T1.[AcctName] LIKE '%Salaries%' THEN 'Salaries'
WHEN T1.[AcctName] LIKE '%Travel%' THEN 'Travel'
WHEN T1.[AcctName] LIKE '%Supplies%' THEN 'Supplies'
WHEN T1.[AcctName] LIKE '%Consultants%' THEN 'Consultants'
WHEN T1.[AcctName] LIKE '%Patient%' THEN 'Patient Care'
WHEN T1.[AcctName] LIKE '%Equipment%' THEN 'Equipments'
WHEN T1.[AcctName] LIKE '%Expense%' THEN 'Other Expenses'
WHEN T1.[AcctName] LIKE '%Alteration%' THEN 'Alterations/Renovations'
ELSE 'Alterations/Renovations'
END as [AcctName],
[AcctCode]
from OACT
) as T1 ON T0.[AcctCode] = T1.[AcctCode]
INNER JOIN OBGS T2 ON T0.[Instance] = T2.[AbsId]
where T2.[Name] = 'Main Budget 2015'
GROUP BY T1.[AcctName]
您可以删除子查询中的别名:
SELECT T1.[AcctName],
SUM(T0.[DebLTotal]/85) AS buget
FROM OBGT T0
INNER JOIN
(
SELECT CASE WHEN [AcctName] LIKE '%Salaries%' THEN 'Salaries'
WHEN [AcctName] LIKE '%Travel%' THEN 'Travel'
WHEN [AcctName] LIKE '%Supplies%' THEN 'Supplies'
WHEN [AcctName] LIKE '%Consultants%' THEN 'Consultants'
WHEN [AcctName] LIKE '%Patient%' THEN 'Patient Care'
WHEN [AcctName] LIKE '%Equipment%' THEN 'Equipments'
WHEN [AcctName] LIKE '%Expense%' THEN 'Other Expenses'
WHEN [AcctName] LIKE '%Alteration%' THEN 'Alterations/Renovations'
ELSE 'Alterations/Renovations'
END as [AcctName],
[AcctCode]
from OAC
) AS T1
ON T0.[AcctCode] = T1.[AcctCode]
INNER JOIN OBGS T2 ON T0.[Instance] = T2.[AbsId]
where T2.[Name] = 'Main Budget 2015'
GROUP BY T1.[AcctName];
重点是别名 T1
在子查询外部定义,因此在内部不可见。
或者你可以在里面添加别名,比如:
SELECT T3.[AcctName],
SUM(T0.[DebLTotal]/85) AS buget
FROM OBGT T0
INNER JOIN
(
SELECT CASE WHEN T1.[AcctName] LIKE '%Salaries%' THEN 'Salaries'
WHEN T1.[AcctName] LIKE '%Travel%' THEN 'Travel'
WHEN T1.[AcctName] LIKE '%Supplies%' THEN 'Supplies'
WHEN T1.[AcctName] LIKE '%Consultants%' THEN 'Consultants'
WHEN T1.[AcctName] LIKE '%Patient%' THEN 'Patient Care'
WHEN T1.[AcctName] LIKE '%Equipment%' THEN 'Equipments'
WHEN T1.[AcctName] LIKE '%Expense%' THEN 'Other Expenses'
WHEN T1.[AcctName] LIKE '%Alteration%' THEN 'Alterations/Renovations'
ELSE 'Alterations/Renovations'
END as [AcctName],
[AcctCode]
from OACT AS T1
) as T3 ON T0.[AcctCode] = T3.[AcctCode]
INNER JOIN OBGS T2 ON T0.[Instance] = T2.[AbsId]
where T2.[Name] = 'Main Budget 2015'
GROUP BY T3.[AcctName]