如何将 datetime 字段设置为 null ?

linlingwei 2013-03-19 12:12:36


insert cb(sc_pihao,end_date)
values(@sc_pihao,@end_date)
上面的语句该如何改正呢?
我想实现这样的功能,如果变量@end_date是空值,就用null写入cb表的end_date字段。这样就防止数据库中
datetime字段默认成‘1900-01-01’了。
...全文
2034 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sololie 2013-03-19
  • 打赏
  • 举报
回复
定义数据表的时候给字段设定默认值

create table dbo.sadmin (
   id   int   identity(1,1)  primary key,
   regdate   datetime  not null default getdate(), 
  ......
simonhehe 2013-03-19
  • 打赏
  • 举报
回复
Parameters.ParamByName('end_date').Value:=null; 或 Parameters.ParamByName('end_date').Value:='null';
linlingwei 2013-03-19
  • 打赏
  • 举报
回复
to feiba7288: with ADOStoredProc1 do begin ProcedureName :='sh_chai'; if Trim(end_date_edit.Text)='' then Parameters.ParamByName('end_date').Value:=nil; ADOStoredProc1.ExecProc; end; 这样做,提示出错, [dcc32 Error] chailing.pas(313): E2010 Incompatible types: 'Variant' and 'Pointer' 平台是xe3
feiba7288 2013-03-19
  • 打赏
  • 举报
回复
参考:http://bbs.csdn.net/topics/390366075
feiba7288 2013-03-19
  • 打赏
  • 举报
回复
你问的是Delphi操作数据库还是? Delphi的话你可以在赋值的时候用: Params.ParamByName('end_date').Value := nil;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧