当前位置: 代码迷 >> Sql Server >> ,得到的值为什么会不一样呢
  详细解决方案

,得到的值为什么会不一样呢

热度:126   发布时间:2016-04-27 14:08:36.0
求救,得到的值为什么会不一样呢?
我有一段程序,主要是得到的时间值为什么不一样呢,具体的程序代码见下:
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)+''''+')')
------解决方案--------------------
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)+''''+')')
  相关解决方案