关于SQL语句执行的问题----can't use empty object or colunm names.user a single space if ne

G

ganh

Unregistered / Unconfirmed
GUEST, unregistred user!
关于SQL语句执行的问题----can't use empty object or colunm names.user a single space if necessary (300分)<br />我有一句SQL语句,在SQL SERVER 的 Query Analyzer 中可以执行 ,但在delhpi中不能执行
提示’can't use empty object or colunm names.user a single space if necessary '
请问如何在程序中将该语句赋值给 adoquery.sql.text 才可以得到结果??
另:很有可能是双引号的问题。

select branch.code as 分公司代码,branch.name as 分公司,fixtype as 维修类型,count(recordcode) as 合计
from record,branch
where branch.name=record.branch
group by branch.code,branch.name,fixtype
union
Select branch.code as 分公司代码,branch.name as 分公司 ,"合计" as 维修类型,count(recordcode) as 合计
from record,branch
where branch.name=record.branch
group by branch.name,branch.code
union
Select "" as 分公司代码,"小计" as 分公司 ,fixtype as 维修类型,count(recordcode) as 合计
from record,branch
where branch.name=record.branch
group by fixtype
union
Select "" as 分公司代码,"总计" as 分公司 ,"" as 维修类型,count(recordcode) as 合计
from record,branch
where branch.name=record.branch
order by branch.code desc
 
试试把双引号改成单引号。
 
1把双引号改成单引号。
2Delphi 不支持汉字别名。
 
Select "" as 分公司代码,"小计" as 分公司 ,fixtype as 维修类型,count(recordcode) as 合计
from record,branch
where branch.name=record.branch
group by fixtype

将里面的""改为单引号看看.Delphi支持汉字别名,我就经常用.
 
有一点可以肯定:你的sql语句不完整

group by 语句,不会是为了省事吧
 
谢谢bbkxjy,zhangkan。我试了,应该把双引号全部换成单引号,就行了。delphi支持汉字别名。

另:g_k_007 这是一句完整的SQL语句,作用是为了在dbgird中生成小计,总计的数据行。

不好意思,还有一个问题,我有这么多单引号,难道在合成SQL语句时不停的加 +'''+ 吗?
有没有什么字符转意的好方法?? (我也穷啊)
 
不必单独地使用 + '''' + 啊,例如:
select ' ' from b
可以写成 adoquery.sql.text := 'select '' '' from b';
不必 adoquery.sql.text := 'select ' + '''' + ' ' + '''' + ' from b';
不知道你是不是这个意思?
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
644
import
I
S
回复
0
查看
822
SUNSTONE的Delphi笔记
S
I
回复
0
查看
751
import
I
顶部