不能Concat选择命令

时间:2017-11-01 07:51:40

标签: sql sql-server tsql

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)) 

2 个答案:

答案 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)
)