CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  数据库相关

SQL语句加入query问题

楼主aldous(一切为了学习)2003-09-02 18:46:53 在 Delphi / 数据库相关 提问

////一个学院里所有欠费的学生  
  select   Distinct   SName,DeptName  
  from(SELECT   Student.SID,Student.SName,Student.SDeptCode  
  FROM   Student,Fee  
  WHERE   Student.SID   IN   (  
  SELECT   Student.SID  
  FROM   Student,Fee  
  WHERE   Student.SID   =   Fee.SID  
  GROUP   BY   Student.SID  
  HAVING   SUM(Fee.FeeDues)   >   SUM(Fee.FeePaid))  
  AND   Student.SID   =   Fee.SID)   as   a,  
  (select   DeptCode,DeptName  
  from   config_SDept  
  where   DeptName   =   '机电工程学院')   as   b  
  where   a.SDeptCode=b.DeptCode  
  这个语句在查询分析器上没有问题。说明不是语句的问题。但是加入query就提示SELECT附近有语法错误。  
  这个写对不对,大家帮我看一下  
   
  strSQL:='select   Distinct   SName,DeptName'+  
                      'from(SELECT   Student.SID,Student.SName,Student.SDeptCode'+  
                      'FROM   Student,Fee'+  
                      'WHERE   Student.SID   IN'+  
                      '(SELECT   Student.SID'+  
                      'FROM   Student,Fee'+  
                      'WHERE   Student.SID   =   Fee.SID'+  
                      'GROUP   BY   Student.SID'+  
                      'HAVING   SUM(Fee.FeeDues)   >   SUM(Fee.FeePaid))'+  
                      'AND   Student.SID   =   Fee.SID)   as   a,'+  
                      '(select   DeptCode,DeptName'+  
                      'from   config_SDept'+  
                      'where   DeptName   =   '''   +   treetext   +   ''')   as   b'+  
                      'where   a.SDeptCode=b.DeptCode';  
          AQPrintN.Close;  
          AQPrintN.SQL.Clear;  
          AQPrintN.SQL.Add(strSQL);  
          AQPrintN.Active:=true;  
          AQPrintN.Open; 问题点数:20、回复次数:5Top

1 楼madyak(无天)回复于 2003-09-02 18:54:03 得分 10

strSQL:='select   Distinct   SName,DeptName'+  
                      '   from(SELECT   Student.SID,Student.SName,Student.SDeptCode'+  
                      '   FROM   Student,Fee'+  
                      '   WHERE   Student.SID   IN'+  
                      '   (SELECT   Student.SID'+  
                      '   FROM   Student,Fee'+  
                      '   WHERE   Student.SID   =   Fee.SID'+  
                      '   GROUP   BY   Student.SID'+  
                      '   HAVING   SUM(Fee.FeeDues)   >   SUM(Fee.FeePaid))'+  
                      '   AND   Student.SID   =   Fee.SID)   as   a,'+  
                      '   (select   DeptCode,DeptName'+  
                      '   from   config_SDept'+  
                      '   where   DeptName   =   '''   +   treetext   +   ''')   as   b'+  
                      '   where   a.SDeptCode=b.DeptCode';  
          AQPrintN.Close;  
          AQPrintN.SQL.Clear;  
          AQPrintN.SQL.Add(strSQL);  
          AQPrintN.Active:=true;  
          AQPrintN.Open;  
  在每行字符串前加一空格试试Top

2 楼madyak(无天)回复于 2003-09-02 18:54:52 得分 0

strSQL:='select   Distinct   SName,DeptName'+  
                      '   from(SELECT   Student.SID,Student.SName,Student.SDeptCode'+  
                      '   FROM   Student,Fee'+  
                      '   WHERE   Student.SID   IN'+  
                      '   (SELECT   Student.SID'+  
                      '   FROM   Student,Fee'+  
                      '   WHERE   Student.SID   =   Fee.SID'+  
                      '   GROUP   BY   Student.SID'+  
                      '   HAVING   SUM(Fee.FeeDues)   >   SUM(Fee.FeePaid))'+  
                      '   AND   Student.SID   =   Fee.SID)   as   a,'+  
                      '   (select   DeptCode,DeptName'+  
                      '   from   config_SDept'+  
                      '   where   DeptName   =   '''   +   treetext   +   ''')   as   b'+  
                      '   where   a.SDeptCode=b.DeptCode';  
          AQPrintN.Close;  
          AQPrintN.SQL.Clear;  
          AQPrintN.SQL.Add(strSQL);  
      //     AQPrintN.Active:=true;这句话多余,最好是去掉  
          AQPrintN.Open;  
  在每行字符串前加一空格试试  
  Top

3 楼huojiehai(海天子)回复于 2003-09-02 18:55:41 得分 0

一楼说得对!!Top

4 楼qianguob(不懂编程)回复于 2003-09-02 19:08:06 得分 0

不错,  
  因为连接起来就不对了。Top

5 楼zhoutian618(秦失其鹿,天下共逐,唯胜者得鹿而割之)回复于 2003-09-02 19:14:49 得分 10

strSQL:='select   Distinct   SName,DeptName'+  
                      +#13#10+'from(SELECT   Student.SID,Student.SName,Student.SDeptCode'+  
                      +#13#10+'FROM   Student,Fee'+  
                      +#13#10+'WHERE   Student.SID   IN'+  
                      +#13#10+'(SELECT   Student.SID'+  
                      +#13#10+'FROM   Student,Fee'+  
                      +#13#10+'WHERE   Student.SID   =   Fee.SID'+  
                      +#13#10+'GROUP   BY   Student.SID'+  
                      +#13#10+'HAVING   SUM(Fee.FeeDues)   >   SUM(Fee.FeePaid))'+  
                      +#13#10+'AND   Student.SID   =   Fee.SID)   as   a,'+  
                      +#13#10+'(select   DeptCode,DeptName'+  
                      +#13#10+'from   config_SDept'+  
                      +#13#10+'where   DeptName   =   '''   +   treetext   +   ''')   as   b'+  
                      +#13#10+'where   a.SDeptCode=b.DeptCode';  
          AQPrintN.Close;  
          AQPrintN.SQL.Clear;  
          AQPrintN.SQL.Add(strSQL);  
          AQPrintN.Active:=true;  
          AQPrintN.Open;  
   
  Top

相关问题

  • 我用query写sql语句.....
  • Query(DBTables)中的SQL语句问题
  • 用query控件,sql语句如何将datetimepicker中的内容添加入数据库中?
  • 求SQL语句
  • sql语句。
  • sql语句?
  • sql 语句?
  • 求SQL语句
  • ***求SQL语句***
  • sql语句??

关键词

  • 语句
  • sql
  • student
  • sid
  • fee
  • aqprintn
  • deptcode
  • sdeptcode
  • deptname
  • feedues

得分解答快速导航

  • 帖主:aldous
  • madyak
  • zhoutian618

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo