Axapta : Use variable in SQL Statement
การรับตัวแปรเพิ่มเข้าไปเป็นเงื่อนไขในส่วนของ SQL เช่น รับค่าจาก Dialog แล้วเอามาเติม Wildcard ก่อนที่จะ query
หากใช้ตัวแปรที่เป็น str ธรรมดาจะมี error message
“Container and unbound string (text) fields are not allowed here in a WHERE expression”
แก้ไขได้โดย กำหนดขนาดของ string ให้แน่นอน หรือประกาศเป็น extended datatype ไปเลย
เช่น
1 2 3 4 5 6 7 8 9 | WrkCtrIdBase tmpStr; str 10 tmpStr2; ; tmpStr = strfmt("%1%2",wrkCtrIdBase,"-LA*"); SELECT SUM(Amount) FROM prodRouteTrans WHERE prodRouteTrans.CategoryId LIKE tmpStr; tmpStr2 = strfmt("%1%2",wrkCtrIdBase,"-LB*"); SELECT SUM(Amount) FROM prodRouteTrans WHERE prodRouteTrans.CategoryId LIKE tmpStr2; |
Written by Komkid on August 13th, 2009 with no comments.
Read more articles on Axapta and Programming.