大家帮我看个SQL2008字符串转换时间问题。执行提示从字符串转换日期和/或时间时,转换失败
(
@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
相关推荐
SQL Server 2008 安装失败后的解决办法
本人第一次安装SQL Server2008 失败之后,就再也安装不上了,经过多次查找资料和试验,终于再次成功安装了,本人亲测。
时间字符串转换成日期对象datetime的方法
代码如下:string ts = “2012-12-19T17:00:00Z”;DateTime dt2 = DateTime.Parse(ts, null, System.Globalization.DateTimeStyles.RoundtripKind);Console.WriteLine(dt2); 您可能感兴趣的文章:sql语句中如何将datetime格式的日期转换为yy-mm-dd格式将WMI中的DateTime类型转换成VBS时间的函数代码LINQ字符串向datetime 转换时失败的处理方法Sql中将datetime转换成字符串的
解析SQL Server中SQL日期转换出错的原因
开发人员有时候使用类似下面SQL将字符串转换为日期时间类型,乍一看,这样的SQL的写法是没有什么问题的。但是这样的SQL其实有时候就是一个定时炸弹,随时可能出现问题(),下面简单对这种情况进行一个简单概括。 SELECT CONVERT(DATETIME, '2020-01-13 6:46:42'); 如果你将连接数据库的登录名的默认语言修改为Aribc,然后去执行上面SQL语句,就会遇到错误,为什么呢? 为什么上面SQL的日期转换出错了呢?其实是因为登录名修改默认语言后,会话对应的date_format变化了,从mdy变成了dmy,所以上面转换就报错了,有时候不报错,但是可能转换成一个错
关于SQL Server 2008 安装提示重新启动计算机失败的解决办法
1、在开始->运行中输入regedit(注册表编辑器)2、到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\3、在右边窗口右击PendingFileRenameOperations,选择删除,然后确认 您可能感兴趣的文章:SQL Server 2008图文安装教程SQL Server 2008 安装和配置图解教程(附官方下载地址)Microsoft SQL Server 2008安装图解教程(Windows 7)sql server 2008安装过程中服务器配
sql2008安装时提示重启计算机失败解决方法.doc
sql2008安装时提示重启计算机失败解决方法.doc


