日期:2014-05-17  浏览次数:20832 次

帮忙看看这句SQL语句,在程序里编译不过?
'Select JH,SJRQ From SGGZ Where gxsjwc is null And (ysjbz=''Y'' or ysjbz is Null) And cjdwdm='''+edtCJDWDM.Text+''' Order by JH'

'Select JH,SJRQ From SGGZ Where gxsjwc is null And (ysjbz=''Y'' or ysjbz is Null) And cjdwdm='''+edtCJDWDM.Text+''' Order by SJRQ Desc'

我是在Delphi里面调用的。

------解决方案--------------------
And (ysjbz=''Y'' or ysjbz is Null) 
and (ysjbz='Y' or ysjbz is null)

无论什么时候,引用常量的时候,应该是单引,而不是双引。
------解决方案--------------------
你跟踪一下,看是什么地方出错,如果是sql.open(s);的地方报错,大多是你的SQL有问题
SQL code

var
   j:string;
begin
   j:='Select JH,SJRQ From SGGZ Where gxsjwc is null And (ysjbz=''Y'' or ysjbz is Null) And cjdwdm='''+edtCJDWDM.Text+''' Order by SJRQ Desc' ;
   ado.sql.clear;
   ado.sql.add(j);
   ado.open();
end;

将下面的SQL在PL/SQL中执行一下,看是不是通过的
Select JH, SJRQ
  From SGGZ
 Where gxsjwc is null
   And (ysjbz = 'Y' or ysjbz is Null)
   And cjdwdm = 'edtCJDWDM'
 Order by SJRQ Desc

------解决方案--------------------
"Select JH,SJRQ From SGGZ Where gxsjwc is null And (ysjbz='Y' or ysjbz is Null) And cjdwdm='''+edtCJDWDM.Text+''' Order by SJRQ Desc"

------解决方案--------------------
单引号和双引号都有问题,
"Select JH,SJRQ From SGGZ Where gxsjwc is null And (ysjbz='Y' or ysjbz is Null) And cjdwdm='"+edtCJDWDM.Text+"' Order by JH"
------解决方案--------------------
ysjbz=''Y'' or ysjbz is Null
这个也可以这样
nvl(ysjbz,'Y')='Y'
主要看你报什么错误
------解决方案--------------------
我在delphi看了你的SQL,字符串组成没有问题,
如下:
Select JH,SJRQ From SGGZ Where gxsjwc is null And (ysjbz='Y' or ysjbz is Null) And cjdwdm='aa' Order by JH

可能是你delphi的ADO连接用户权限问题吧,
或者你的adodataset连接问题;

------解决方案--------------------
贴出Delphi代码来
------解决方案--------------------
探讨
Select JH,SJRQ,SQRQ,cjdwdm From SGGZ Where gxsjwc is null And (ysjbz='Y' or ysjbz is Null) Order by JH
PL/SQL 里面是可以运行得出正确结果的。
但是程序里面没结果呀。