setsqlselect()的问题

novice2008 2009-05-15 09:19:39
有2个表
teacher
{
T# //教师号
tname //教师姓名
}

course
{
cname char(10) //课程名
T# char(10)(teacher的外码)
}

根据教师号查询教师姓名和课程。要求要有动态SQL语句
我的代码不知道哪里错了

string code
string old_select
string condition
string tmp1, tmp2, tmp3

tmp1 = trim(sle_1.text)

select tname
into :tmp2
from teacher
where trim(t#) =:tmp1;

select cname
into :tmp3
from course
where trim(t#) =:tmp1;

old_select = dw_1.getsqlselect()
condition = "where teacher.tname = '"+tmp2+"'"
condition += "and teacher.cname = '"+tmp3+"'"
condition = old_select + condition
dw_1.setsqlselect(condition)
dw_1.retrieve()
...全文
168 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
fjgzqjh 2009-05-19
  • 打赏
  • 举报
回复
sql 沒有trim()函數
novice2008 2009-05-19
  • 打赏
  • 举报
回复
原来这样啊

如果拿一个没有空格的字符串,和一个末尾有空格的相同字符串比较,会相同吗?
newease 2009-05-19
  • 打赏
  • 举报
回复
你设计的字段类型是char 如果数据长库不足char设置,会自己补空值
fjgzqjh 2009-05-18
  • 打赏
  • 举报
回复

select tname
into :tmp2
from teacher
where ltrim(t#) =:tmp1
novice2008 2009-05-18
  • 打赏
  • 举报
回复
的确可以取出了,为什么改成ltrim()就行了呢
builderwfy 2009-05-17
  • 打赏
  • 举报
回复
一般用messagebox来看提示什么,看你的SQL语句是不是有问题,一般都是少了空格之类的
newease 2009-05-17
  • 打赏
  • 举报
回复
select teacher.t#,teacher.tname,course.cname
from course,teacher
where (course.t# = teacher.t#) and teacher.tname = " and teacher.cname = "
显示Sql语法是正确的


你用messagebox或DBUG,查看 tmp2 和tmp3 是否取出值来了

我猜想应该是tmp2 tmp3 没有取出值

所以才会and teacher.tname = " and teacher.cname = "
novice2008 2009-05-17
  • 打赏
  • 举报
回复
我tmp2,tmp3果然没取出,是什么原因呢?
bibidbzfish 2009-05-16
  • 打赏
  • 举报
回复
这句dw_1.setsqlselect(condition) 后面要跟个Dw_1.Settransobject(Sqlca)
rightyeah 2009-05-16
  • 打赏
  • 举报
回复
1、条件前后要保留足够多的空格,不要吝啬这么一个字符。我习惯在and、where前面加上一个空格的。
2、不要轻易用where、除非你能确定原来的sql语句中,没有用过
3、拼接好的sql,可以用messagebox显示出来,先看看有没有问题再说

novice2008 2009-05-16
  • 打赏
  • 举报
回复
用messagebox果然是个好方法

old_selct里面是

select teacher.t#,teacher.tname,course.cname
from course,teacher
where course.t# = teacher.t#

所以我把condition条件改成
condition = "and teacher.tname = '"+tmp2+"'"
condition += " and teacher.cname = '"+tmp3+"'"
condition = old_select + condition

messagebox显示的是
select teacher.t#,teacher.tname,course.cname
from course,teacher
where (course.t# = teacher.t#) and teacher.tname = " and teacher.cname = "
为什么tmp2和tmp3的值没有显示呢??却显示了2 引号?
newease 2009-05-16
  • 打赏
  • 举报
回复
old_selectt = dw_1.getsqlselect()
你得到的数据窗口的语法是什么内容

使用setsqlselect

关键是 condition = old_select + condition 取值和设置是否正确

如果你old_select语句包括 where /order by/ group by等

你直接加condition(只直写where 条件 或者 and 条件之类的 )

你得到的condition一定不是正确的,当然无法执行了


请按上述说明进行检查

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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