sql.add('select * from record where location like :temp1 and build like :temp2 and room like :temp3');
parambyname('temp1').asstring:='%'+trim(locaEdit.Text)+'%';
parambyname('temp2').asstring:='%'+trim(buildEdit.Text)+'%';
parambyname('temp3').asstring:='%'+trim(roomEdit.Text)+'%';如果3个Edit均不输内容,期望查询到的是全库内容,但结果是只有location/build/room三个字段都有值的才能查询到。若3者之中有一个为空(NULL)则不行。问题:DELPHI中的'%'+trim(roomEdit.Text)+'%',当edit.text=''时不能获取SQL SERVER中的NULL值?
parambyname('temp1').asstring:='%'+trim(locaEdit.Text)+'%';
parambyname('temp2').asstring:='%'+trim(buildEdit.Text)+'%';
parambyname('temp3').asstring:='%'+trim(roomEdit.Text)+'%';如果3个Edit均不输内容,期望查询到的是全库内容,但结果是只有location/build/room三个字段都有值的才能查询到。若3者之中有一个为空(NULL)则不行。问题:DELPHI中的'%'+trim(roomEdit.Text)+'%',当edit.text=''时不能获取SQL SERVER中的NULL值?
解决方案 »
- 关于指针小疑问
- 在命令行程序中使用线程出现的问题
- 腾迅QQ六周年,六位QQ号不要钱!http://www.QQ.com.Qb.daqi8.com/QQ/vip.htm?QQ=966858&fromid=785778211027
- 我想做一个类似Google的IE工具条,有做过的吗?帮帮忙
- 怎样对日期进行查询
- 一个简单的问题
- 如何分发?
- 请大家帮帮忙!这个语句能通过吗?
- 怎样将String转换为PChar?谢谢!(在使用SendMessage)
- 开发WEB服务嚣时,调用了DELPHI的ActiveFrom。当移动一下工具条时,DELPHI的ActiveFrom一片混乱。
- delphi 中如何用keybd_event 实现对其他应用程序的模拟键盘输入(例如:对WORD,文本等)
- 如何使每次产生的随机数序列不同?
UP......
写详细一点
sql.add('select * from record where ((location like :temp1) or (location is null)) and ((build like :temp2) or (build is null)) and ((room like :temp3')or (room is null));
parambyname('temp1').asstring:='%'+trim(locaEdit.Text)+'%';
parambyname('temp2').asstring:='%'+trim(buildEdit.Text)+'%';
parambyname('temp3').asstring:='%'+trim(roomEdit.Text)+'%';
再换个方式把
sql.add('select * from record where ((location like :temp1) or ((location is null) and (:temp1=''%%''))) and ((build like :temp2) or ((build is null) and (:temp2=''%%'')) and ((room like :temp3)or ((room is null) and (:temp3=''%%''))';这样应该完全可以达到要求了
有问题请发信息到我的E-mail:[email protected]
你的sql.text分开来写嘛
User输入了多少个Edit,你sql.text中就有多少个参数。
如:if trim(Edit1.text)<>'' then
sql.text:=
if Trim(edit2.text)<>'' then
…………
我希望的就是niat97222(Freeman)说的第二种情况。
但你的语句好象括号上有问题吧?调试不过~~~
我添成以下这样,语法上没问题了,但运行查询后抱错:invalid token:))
不知错在哪里?
谢谢各位~! sql.add('select * from record where ((location like :temp1) or ((location IS NULL) and (:temp1=''%%''))) and ((build like :temp2) or ((build IS NULL) and (:temp2=''%%''))) and ((room like :temp3) or ((room IS NULL) and (:temp3=''%%'')))');