select 'HP00'+ select CAST(select((select count(policyIdPolicy)
from #temp where policyIdPolicy Not like 'Hp%')-
(select count(policyIdPolicy) from #temp
where policyIdPolicy like 'Hp%')) AS VARCHAR(10))
答案 0 :(得分:1)
分别选择每个部分,然后连续。
<强>查询强>
select 'HP00' + cast((t.col_1 - t.col_2) as varchar(max)) from(
select
sum(case when policyIdPolicy like 'Hp%' then 1 else 0 end) as col_1,
sum(case when policyIdPolicy not like 'Hp%' then 1 else 0 end) as col_2
from #temp
)t;
答案 1 :(得分:0)
试试这个:
select 'HP00'+
CAST
(
(
(select count(policyIdPolicy)
from #temp
where policyIdPolicy Not like 'Hp%'
)
-
(select count(policyIdPolicy)
from #temp
where policyIdPolicy like 'Hp%')
) AS VARCHAR(10)
)