我正在尝试执行包含多个子查询的 SQL 查询,然后将其中的某些部分分配给局部变量。不幸的是,我在获取语法正确时遇到了问题。
我的查询如下
declare @temp1 varchar(200)
declare @temp2 varchar(200)
select case when cnt>0 then 'RouteA' else 'RouteB' end as Route from
( select
(
(select case when (req.Avg > 10) then 1 else 0 end from
(select count(val) as Avg from T1) req) +
(select case when (req.Avg > 10) then 1 else 0 end from
(select count(val) as Avg from T2) req)
) as cnt) t
我需要做的是将以下子查询的值分配给@temp1:
(select case when (req.Avg > 10) then 1 else 0 end from
(select count(val) as Avg from T1) req)
这个对 temp2 的子查询:
(select case when (req.Avg > 10) then 1 else 0 end from
(select count(val) as Avg from T2) req)
我已经尝试了多种方法,但不断收到语法错误。
任何帮助,将不胜感激!
谢谢你,查理