我有一段程序,主要是得到的时间值为什么不一样呢,具体的程序代码见下:
declare @log_userid varchar(4)
declare @log_username varchar(20)
declare @log_hostip varchar(128)
declare @log_hostname varchar(256)
declare @log_time datetime
select @log_time=getdate() from ss_get_datetime
select @log_time
set @log_userid='0003'
set @log_username='test'
set @log_hostip='192.168.1.109'
set @log_hostname='testhost'
declare @tablename varchar(128)
set @[email protected]_userid
exec('create Table [email protected]+'(loguserid varchar(4),logusername varchar(20),loghostip varchar(128),loghostname varchar(256),logtime datetime)')
exec('insert into [email protected]+'(loguserid,logusername,loghostip,loghostname,logtime) values([email protected]_userid+''''+',[email protected]_username+''''+',[email protected]_hostip+''''+',[email protected]_hostname+''''+',[email protected]_time+''''+')')
exec('select * from [email protected])
注意看两个日期时间型数据,为什么后面一个没有秒数,而前一个有具体的秒数呢?
请高手帮忙解决,谢谢
------解决方案--------------------
试试
exec('insert into [email protected]+'(loguserid,logusername,loghostip,loghostname,logtime) values([email protected]_userid+''''+',[email protected]_username+''''+',[email protected]_hostip+''''+',[email protected]_hostname+''''+','+''''+convert(varchar(23),@log_time,120)+''''+')')
------解决方案--------------------
convert(varchar(23),@log_time,120)
------解决方案--------------------
- SQL code
exec('insert into [email protected]+'(loguserid,logusername,loghostip,loghostname,logtime) values([email protected]_userid+''''+',[email protected]_username+''''+',[email protected]_hostip+''''+',[email protected]_hostname+''''+','+''''+convert(varchar(19),@log_time,120)+''''+')')