【发布时间】:2016-01-08 10:12:26
【问题描述】:
消息 512,级别 16,状态 1,过程 GetNews2,第 27 行子查询 返回超过 1 个值。子查询时不允许这样做 遵循 =、!=、、>= 或当子查询用作 表达。消息 512,级别 16,状态 1,过程 GetNews2,第 32 行 子查询返回超过 1 个值。这是不允许的,当 子查询遵循 =、!=、、>= 或当子查询用作 一种表达。消息 512,级别 16,状态 1,过程 GetNews2,第 36 行 子查询返回超过 1 个值。这是不允许的,当 子查询跟在 =, !=, , , >= 之后,或者当 子查询用作表达式。消息 512,级别 16,状态 1, 过程 GetNews2,第 40 行子查询返回超过 1 个值。这个 当子查询跟随 =、!=、、>= 或 当子查询用作表达式时。
alter proc GetNews2
(@GetCustomerTable [dbo].[CustomerTableType] readonly,
@GetProjectTable [dbo].[ProjectTableType] readonly )
as
begin
set nocount on
CREATE table #newsTemp( NewsId BIGINT,
Title nchar(550),
[Description] NVARCHAR(max),
CreatedDate Datetimeoffset,
CreatedBy int,
IsDeleted bit,
CustomerId INT,
Projectid INT)
;WITH Getnew_cte (NewsId,Title,[Description],CreatedDate,CreatedBy,IsDeleted,CustomerId,ProjectId)
as
(
select N.NewsId,N.Title,N.[Description],N.CreatedDate,N.CreatedBy,N.IsDeleted,ct.CustomerId,pt.ProjectId from News N
full join CustomersNews ct on N.NewsId = ct.NewsId
full join ProjectsNews pt on N.NewsId = pt.NewsId
)
insert into #newsTemp
select NewsId,Title,[Description],CreatedDate,CreatedBy,IsDeleted,CustomerId,ProjectId from Getnew_cte
if
((select * from @GetCustomerTable) IS NULL and (select * from @GetProjectTable) is null)
begin
(select * from #newsTemp where #newsTemp.CustomerId Is nulL and #newsTemp.ProjectId is null )
end
if ((select * from @GetCustomerTable) is null) and ((select * from @GetProjectTable) is not null)
begin
(select * from #newsTemp where #newsTemp.CustomerId Is null and #newsTemp.ProjectId in (select projectId from @GetProjectTable))
end
if ((select *from @GetCustomerTable) is not null) and ((select * from @GetProjectTable) is null)
begin
(select * from #newsTemp where #newsTemp.CustomerId in (select CustomerId from @GetCustomerTable) and #newsTemp.ProjectId is null)
end
if ((select * from @GetCustomerTable) is not null) and ((select * from @GetProjectTable) is not null)
begin
(select * from #newsTemp where ((#newsTemp.CustomerId in (select CustomerId from @GetCustomerTable)) and (#newsTemp.ProjectId in (select projectId from @GetProjectTable))))
end
end
【问题讨论】:
-
由于您是 SO 新手,请允许我提示:请注意,所有在 SO 上提供答案的专业人士都渴望获得声誉积分。请阅读this: someone-answers。谢谢!
标签: sql-server-2008