目前的SQL:
select a.*,(select Count(ID) From uploadFile where objectType =a.TypeID) AS UploadFileCount From activity as a
就是弄不清楚,要如何加判断,当count记录数为零时,UploadFileCoun赋值作字符串''。

解决方案 »

  1.   

    select a.*,(select case when Count(ID)=0 then '' else Count(ID) end From uploadFile where objectType =a.TypeID) AS UploadFileCount From activity as a
      

  2.   

    谢谢Dlut_LIuQ的回复,用Count(ID)=0 then '',没有我要的效果,还是输出0,当我把''改成字符串 时候,报异常' ' 将varchar 值转换为数据类型int 的列时发生语法错误。
    继续求解!!
      

  3.   

    select a.*,
    case when (select Count(ID) From uploadFile where objectType =a.TypeID)=0 then ''else 'a' end  AS UploadFileCount 
    From activity as a
      

  4.   

    select a.*,(select case when Count(ID)=0 then '' else ltrim(Count(ID)) end From uploadFile where objectType =a.TypeID) AS UploadFileCount From activity as a
      

  5.   

    果然是高手,可以了,我还用Convert函数试了n久.