请教动态SQL问题

pingj 2003-03-05 01:06:50
我在脚本里定义一STRING变量,其内容是动态SQL语句,请问怎样把DATETIME型变量嵌到字符串中?如下:
i_sql = " where date between ( ? and ?)"
请问?处的格式怎样写?
...全文
71 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
joachern 2003-03-05
  • 打赏
  • 举报
回复
要是对oracle而言,可能可能要用to_date()函数!
dotnba 2003-03-05
  • 打赏
  • 举报
回复
dynamic sql
cyactiveboy 2003-03-05
  • 打赏
  • 举报
回复
up
andyzq 2003-03-05
  • 打赏
  • 举报
回复
datetime ldt_start, ldt_end
string ls_sql

ls_sql = " where date between " + "'" + string(ldt_start,'yyyy-mm-dd hh:mm:ss') + "'" + "and" + "'" + string(ldt_end,'yyyy-mm-dd hh:mm:ss') + "'"

ls_sql = " where date between " + "'" + string(ldt_start,'yyyy-mm-dd') + " " + string(ldt_start,'hh:mm:ss') + "'" + &
"and" + "'" + string(ldt_end,'yyyy-mm-dd') + " " + string(ldt_start,'yyyy-mm-dd') + " " + string(ldt_end,'hh:mm:ss') + "'"
pingj 2003-03-05
  • 打赏
  • 举报
回复
to andyzq(小强):
你的语句对DATE型有效,DATETIME型后面还有HH:MM:SS,怎样处理呢?

另请各位诊断一段SCRIPT:
int li_value
string i_condition1,i_condition2,i_condition3,i_sql
datetime i_date1,i_date2

i_date1 = DateTime(Date(em_1.text),00:00:00)
i_date2 = DateTime(Date(em_2.text),23:59:59)

i_sql = "select count(wz_b_guidang.i_eworkno) from wz_work_no_define,wz_b_guidang" +&
" where wz_work_no_define.work_no=wz_b_guidang.i_workno"

i_condition1 = " and wz_b_guidang.i_intime >= ? and i_intime <= ? "


Choose Case i_dwtype
Case 1
i_condition3 = " and wz_work_no_define.business_kind= ? "
Case 2
i_condition3 = " and wz_work_no_define.business_type= ? "
Case 3
i_condition3 = " and wz_work_no_define.work_no= ? "
End Choose

i_sql = i_sql + i_condition1 + i_condition3

Declare cur_value Dynamic Cursor For SQLSA;
PREPARE SQLSA FROM :i_sql;
Open Dynamic cur_value Using :i_date1,:i_date2,:i_busi_id;
Fetch cur_value into :li_value;
Close cur_value;

单独执行SQL语句能查出结果,但程序里调试时变量没有结果
andyzq 2003-03-05
  • 打赏
  • 举报
回复
datetime ldt_start, ldt_end
string ls_sql
ls_sql = " where date between " + "'" + string(ldt_start,'yyyy-mm-dd') + "'" + "and" + "'" + string(ldt_start,'yyyy-mm-dd') + "'"
xwffwx 2003-03-05
  • 打赏
  • 举报
回复
在sybase中可以这么写
i_sql = " where date between ('2001-01-01' and '2001-12-31 23:59:59')"
可以自动转换

743

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 脚本语言
社区管理员
  • 脚本语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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