oetjoen
5th January 2007, 08:32
Hi, Guru

I'm trying to using sql operand with where like condition with variable in my report script, here is the part of script

...
long maxno
domain tc.mcsstr5 serno
domain tc.mcsstr2 year2

year2 = sprintf$("%u(%02y)", utc.num())
serno = "0__" & year2

select cisli986.*
from cisli986
where cisli986._index1 = {:cisli205.ityp, :cisli205.idoc}
selectdo
selectempty
select max(cisli986.txno):maxno
from cisli986
where cisli986.srno like :serno
selectdo
endselect
endselect
...

I got error message from compile

Error SQL: Syntax error: ':serno' not expected

How to solve
Thanks for help
Oetjoen

Hiba_t
5th January 2007, 09:54
Check this, It should help you..

http://www.baanboard.com/baanboard/showthread.php?t=26222&highlight=select+sql+variable

Hitesh Shah
6th January 2007, 16:31
Though u will be able to use like operator only in dynamic query , u also need to know the rules of regular expression (which u can c in the help of exp.compile ). Only when u use special characters like . (dot) , * (asterisk) , $ (dollar) , ^ (caret) etc , u gain the result of like operator . I did not c any of that in serno variable used by u .

_Ralph_
8th January 2007, 18:30
Search something about Dynamic SQL it may help you

oetjoen
9th January 2007, 04:12
Hi All,

Thx for help. Finally i have finished my script following this post
qptool select on like or substring (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=8763&highlight=substring)

Thx all. u r the best :)

Here is my script

...
long maxno
domain tc.mcsstr5 serno
domain tc.mcsstr2 year2

year2 = sprintf$("%u(%02y)", utc.num())
serno = "0"

select cisli986.*
from cisli986
where cisli986._index1 = {:cisli205.ityp, :cisli205.idoc}
selectdo
selectempty
select max(cisli986.txno):maxno
from cisli986
where cisli986.srno(1;1) = :serno
and cisli986.srno(4;2) = :year2
selectdo
endselect
endselect
...