如何在sql server 2008中插入日期 [英] how to insert date in sql server 2008

查看:179
本文介绍了如何在sql server 2008中插入日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下表

 创建  newemprequest(jobid 
,jobcategory
,[技能]
,[opendate] date
, [enddate] date
,[experiencerequired]
,[numberofvacancies]
,[jobdescription])



i我在插入查询下面

  insert  进入 newemprequest  1 '  canesection''  canecutter' ,10-10-13,20-10-13, 2  10 ,< span class =code-string>'  jfkadsklflskfd'



我收到以下错误:

操作数类型冲突:int与日期不兼容任何一个帮助我如何在sql server 2008中插入日期。

解决方案





简单....查看任何INSERT语句样本...

  INSERT   INTO  newemprequest(jobid,jobcategory,skill,opendate,enddate ,experienceexquired,numberofvacancies,jobdescription)
VALUES 1 ' canesection'' canecutter'' 2013-10-10'' 2013-10-20' 2 10 ' jfkadsklflskfd'



你必须遵循一些标准....以YYYY-MM-DD格式提供所有列名和日期值...检查以下链接

INSERT示例(Transact-SQL) [ ^ ]

简单SQL Server INSERT语句 [ ^ ]

SQL INSERT INTO语句 [ ^ ]

SQL SERVER - 2008 - 使用一个插入语句插入多个记录 - 使用行构造函数 [ ^ ]



问候,

GVPrabu


< blockquote>尝试:

 插入 进入 newemprequest  values  1 '  canesection''  canecutter''  10-10-2013''  20-10-2013' 2  10 ,'  jfkadsklflskfd'

但请注意,SQL默认为ISO日期格式:yyyy-MM-dd,如果可能的话,使用它是一个非常好的主意......


当我使用任何日期值到表我总是使用yyyy-MM-dd ISO格式。



插入表(DateField)值('2013-12-01');



如果您遵循这种模式,那么它也适用于其他数据库。


i am using the below table

create table newemprequest(jobid
      ,jobcategory
      ,[skill]
      ,[opendate] date
      ,[enddate] date
      ,[experiencerequired]
      ,[numberofvacancies]
      ,[jobdescription])


i am inserting below query

insert into newemprequest values(1,'canesection','canecutter',10-10-13,20-10-13,2,10,'jfkadsklflskfd')


I got following error :
Operand type clash: int is incompatible with date any one help me how to insert date in sql server 2008.

解决方案

Hi,

Its simple .... check any INSERT Statement Sample...

INSERT INTO newemprequest(jobid, jobcategory, skill, opendate, enddate, experiencerequired, numberofvacancies, jobdescription)
VALUES(1,'canesection','canecutter', '2013-10-10', '2013-10-20',2,10,'jfkadsklflskfd')


You have to follow some standards.... like give all column names and date values in YYYY-MM-DD Format ext... check the below links
INSERT Examples (Transact-SQL)[^]
Simple SQL Server INSERT statement[^]
SQL INSERT INTO Statement[^]
SQL SERVER – 2008 – Insert Multiple Records Using One Insert Statement – Use of Row Constructor[^]

Regards,
GVPrabu


Try:

insert into newemprequest values(1,'canesection','canecutter','10-10-2013','20-10-2013',2,10,'jfkadsklflskfd')

But be aware that SQL defaults to ISO date format: yyyy-MM-dd and it is a very good idea to use it if at all possible...


When I use any date value to table i always use yyyy-MM-dd ISO format.

Insert into Table(DateField) values ('2013-12-01');

If you follow this pattern then it will work other database too.


这篇关于如何在sql server 2008中插入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆