大家帮我看个SQL2008字符串转换时间问题。执行提示从字符串转换日期和/或时间时,转换失败
ALTER proc [dbo].[Sp_tj_Sjtj]
(
@Communityid varchar(10),
@type varchar(5) ,
@Stime datetime, --开始时间
@Etime datetime --截止时间
)
as
begin
declare @strsql varchar(8000),
@name varchar(20),
@where varchar(50)
if @Communityid='0' or @Communityid='' or @Communityid =null or @Communityid is null
set @Communityid ='null'
IF @Stime = ''
SET @Stime = NULL
IF @Etime = ''
SET @Etime = NULL
if(@type='1')
begin
set @name='TypeName'
set @where='t.Typeid';
end
else if(@type='2')
begin
set @name='FlowCategoryName'
set @where='fc.FlowCategoryid';
end
else
begin
set @name='FlowName'
set @where='f.Flowid';
end
set @strsql ='
select isnull( '+@name+',''未知'') name ,COUNT(cid) as ''合计'','+@where+' id from tblCase c
left join tblFlow f on c.Flowid=f.Flowid
left join tblFlowCategory fc on f.FlowCategoryid =fc.FlowCategoryid
left join tblType t on fc.typeid=t.Typeid where
(CommunityID='+@Communityid+' or '+@Communityid+' is null)
and (CONVERT(varchar(100),c.HappenTime,23)>='+@Stime+' or '+@Stime+' is null)
and (CONVERT(varchar(100),c.HappenTime,23)<='+@Etime+' or '+@Etime+' is null)
group by '+@where+','+@name+'
order by ''合计'' desc'
exec(@strsql)
end