无法像程序语言那样写SQL查询语句,提示“数据库中已存在名为 '#temp1' 的对象。”

 if exists(
    select 
        exp_count
    from
        tbl_expend
    where 
        exp_valid = 1 and exp_public = 0 and exp_monthly = 0 and  convert(varchar(7),exp_date,120) = convert(varchar(7),cast('2020/04/03 22:57:20'as datetime ),120)  
)
    begin
        select 
            exp_count
        into #temp1
        from
            tbl_expend
        where 
            exp_valid = 1 and exp_public = 0 and exp_monthly = 0 and  convert(varchar(7),exp_date,120) = convert(varchar(7),cast('2020/04/03 22:57:20'as datetime ),120)  
    end
else
    begin
        select 0 as exp_count into #temp1        
    end
    

原文地址:https://www.cnblogs.com/bamboo-140/p/12649933.html