更新存储过程没有获取列
Update stored procedure no getting column
我有这个存储过程:
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalYEAR
INTO
#AuditYear
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
YEAR(aa.CreateDate) = (SELECT YEAR
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalMonth
INTO
#AuditMonth
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
MONTH(aa.CreateDate) = (SELECT MONTH
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description
SELECT
y.IdCategory, y.Category,
ISNULL(m.TotalMonth,0) AS TotalMonth,
y.TotalYEAR
FROM
#AuditYear y
LEFT JOIN
#AuditMonth m ON y.IdCategory = m.IdCategory
我想添加名为 BranchOfficeId
的列,所以我做了一个 INNER JOIN
,例如:
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalYEAR,
b.BranchOfficeId
INTO
#AuditYear
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[Department] AS d (NOLOCK) ON aa.IdDepartment = d.Id
INNER JOIN
[dbo].[BranchOffice] AS b (NOLOCK) ON b.BranchOfficeId = d.BranchOfficeId
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
YEAR(aa.CreateDate) = (SELECT YEAR
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description, b.BranchOfficeId
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalMonth
INTO
#AuditMonth
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
MONTH(aa.CreateDate) = (SELECT MONTH
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description
SELECT
y.IdCategory, y.Category,
ISNULL(m.TotalMonth,0) AS TotalMonth,
y.TotalYEAR
FROM
#AuditYear y
LEFT JOIN
#AuditMonth m ON y.IdCategory = m.IdCategory
但是当我更新我的复杂类型时它只得到列:
public int IdCategory { get; set; }
public string Category { get; set; }
public int TotalMonth { get; set; }
public Nullable<int> TotalYEAR { get; set; }
谁能解释一下为什么我无法获得 BranchOfficeId
值?问候
SELECT y.IdCategory
,y.Category
,ISNULL(m.TotalMonth,0) AS TotalMonth
,y.TotalYEAR
FROM #AuditYear y
LEFT JOIN #AuditMonth m
ON y.IdCategory = m.IdCategory
#AuditYear 是您第一个 select 的结果,那么,您只需要最后一个 select:
中的列 BranchOfficeId
SELECT y.IdCategory
,y.Category
,ISNULL(m.TotalMonth,0) AS TotalMonth
,y.TotalYEAR, y.BranchOfficeId
FROM #AuditYear y
LEFT JOIN #AuditMonth m
ON y.IdCategory = m.IdCategory
我有这个存储过程:
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalYEAR
INTO
#AuditYear
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
YEAR(aa.CreateDate) = (SELECT YEAR
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalMonth
INTO
#AuditMonth
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
MONTH(aa.CreateDate) = (SELECT MONTH
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description
SELECT
y.IdCategory, y.Category,
ISNULL(m.TotalMonth,0) AS TotalMonth,
y.TotalYEAR
FROM
#AuditYear y
LEFT JOIN
#AuditMonth m ON y.IdCategory = m.IdCategory
我想添加名为 BranchOfficeId
的列,所以我做了一个 INNER JOIN
,例如:
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalYEAR,
b.BranchOfficeId
INTO
#AuditYear
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[Department] AS d (NOLOCK) ON aa.IdDepartment = d.Id
INNER JOIN
[dbo].[BranchOffice] AS b (NOLOCK) ON b.BranchOfficeId = d.BranchOfficeId
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
YEAR(aa.CreateDate) = (SELECT YEAR
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description, b.BranchOfficeId
SELECT
s.Id AS IdCategory,
s.Description AS Category,
COUNT(s.Description) AS TotalMonth
INTO
#AuditMonth
FROM
[dbo].[Audit] aa (NOLOCK)
INNER JOIN
[dbo].[AuditActOrCondition] a (NOLOCK) ON aa.Id = a.IdAudit
INNER JOIN
[dbo].[ActOrCondition] ac (NOLOCK) ON a.IdActCondition = ac.Id
INNER JOIN
[dbo].[ACType] t (NOLOCK) ON ac.Type = t.Id
INNER JOIN
[dbo].[ACSubType] s (NOLOCK) ON ac.Subtype = s.Id
WHERE
MONTH(aa.CreateDate) = (SELECT MONTH
FROM [dbo].[KPIS] k1 (NOLOCK)
WHERE k1.Id = @Id)
GROUP BY
s.Id, s.Description
SELECT
y.IdCategory, y.Category,
ISNULL(m.TotalMonth,0) AS TotalMonth,
y.TotalYEAR
FROM
#AuditYear y
LEFT JOIN
#AuditMonth m ON y.IdCategory = m.IdCategory
但是当我更新我的复杂类型时它只得到列:
public int IdCategory { get; set; }
public string Category { get; set; }
public int TotalMonth { get; set; }
public Nullable<int> TotalYEAR { get; set; }
谁能解释一下为什么我无法获得 BranchOfficeId
值?问候
SELECT y.IdCategory
,y.Category
,ISNULL(m.TotalMonth,0) AS TotalMonth
,y.TotalYEAR
FROM #AuditYear y
LEFT JOIN #AuditMonth m
ON y.IdCategory = m.IdCategory
#AuditYear 是您第一个 select 的结果,那么,您只需要最后一个 select:
中的列 BranchOfficeIdSELECT y.IdCategory
,y.Category
,ISNULL(m.TotalMonth,0) AS TotalMonth
,y.TotalYEAR, y.BranchOfficeId
FROM #AuditYear y
LEFT JOIN #AuditMonth m
ON y.IdCategory = m.IdCategory