UniDAC AddWhere procedure error occurrence!
Source code example.
.....
UniQuery1.AddWhere(' Field_Name LIKE '''+Edit1.Text+'%'' ');
.....
When execution error occurrence.
"Column name 'Field_Name' incorrect."
In use UniDac latest version(3.5).
Please test and reply.
UniDAC AddWhere procedure error!
-
- Posts: 31
- Joined: Sun 27 Jun 2010 20:50
Re: UniDAC AddWhere procedure error!
Make sure there is column Field_Name in your table . I tried it, no error.ibdac1pro wrote:UniDAC AddWhere procedure error occurrence!
Source code example.
.....
UniQuery1.AddWhere(' Field_Name LIKE '''+Edit1.Text+'%'' ');
.....
When execution error occurrence.
"Column name 'Field_Name' incorrect."
In use UniDac latest version(3.5).
Please test and reply.
Hello,
I can not reproduce the problem.
Please specify your database name and version.
Check that the "Field_Name" column really exists in the table.
Also please set the TUniQuery.Debug property to true (you should add the UniDACVcl unit to the uses clause of any unit in your project to make the Debug property work) and check the query text after execution.
I can not reproduce the problem.
Please specify your database name and version.
Check that the "Field_Name" column really exists in the table.
Also please set the TUniQuery.Debug property to true (you should add the UniDACVcl unit to the uses clause of any unit in your project to make the Debug property work) and check the query text after execution.
DataBase Name: Sql Server 2008 SP2
Really Table and Query(SQL) Text.
-------------------------------------------------------------------
WITH GetItemSum ( ItemSeq, ATOT, QTOT )
AS ( SELECT B.ItemSeq,
ISNULL(SUM(B.DomAmt), 0) ATOT,
ISNULL(SUM(B.Qty), 0) QTOT
FROM _TSLInvoice A
JOIN _TSLInvoiceItem B ON A.CompanySeq = B.CompanySeq
AND A.InvoiceSeq = B.InvoiceSeq
WHERE A.CompanySeq = 1
AND A.InvoiceDate BETWEEN '20070101' and '20070531'
GROUP BY B.ItemSeq )
SELECT A.*, B.ItemNo, B.ItemName
FROM GetItemSum A
JOIN _TDAItem B ON A.ItemSeq = B.ItemSeq
AND B.CompanySeq = 1
-------------------------------------------------------------------
Program source.
AddWhere(' B.ItemName LIKE '''+Item.Text+'%'' '); ==> Error
AddWhere(' B.ItemNo LIKE '''+Item.Text+'%'' '); ==> Error
Unrecognized field : 'B.ItemName', 'B.ItemNo'
AddWhere(' A.ItemSeq LIKE '''+Item.Text+'%'' '); ==> No Error
AddWhere(' A.QTOT > 0 '); ==> No Error
Recognized field : 'A.ItemSeq', 'A.QTOT'
I'm used WITH statement.
Testing under WITH statement.
Please test and replay.
Really Table and Query(SQL) Text.
-------------------------------------------------------------------
WITH GetItemSum ( ItemSeq, ATOT, QTOT )
AS ( SELECT B.ItemSeq,
ISNULL(SUM(B.DomAmt), 0) ATOT,
ISNULL(SUM(B.Qty), 0) QTOT
FROM _TSLInvoice A
JOIN _TSLInvoiceItem B ON A.CompanySeq = B.CompanySeq
AND A.InvoiceSeq = B.InvoiceSeq
WHERE A.CompanySeq = 1
AND A.InvoiceDate BETWEEN '20070101' and '20070531'
GROUP BY B.ItemSeq )
SELECT A.*, B.ItemNo, B.ItemName
FROM GetItemSum A
JOIN _TDAItem B ON A.ItemSeq = B.ItemSeq
AND B.CompanySeq = 1
-------------------------------------------------------------------
Program source.
AddWhere(' B.ItemName LIKE '''+Item.Text+'%'' '); ==> Error
AddWhere(' B.ItemNo LIKE '''+Item.Text+'%'' '); ==> Error
Unrecognized field : 'B.ItemName', 'B.ItemNo'
AddWhere(' A.ItemSeq LIKE '''+Item.Text+'%'' '); ==> No Error
AddWhere(' A.QTOT > 0 '); ==> No Error
Recognized field : 'A.ItemSeq', 'A.QTOT'
I'm used WITH statement.
Testing under WITH statement.
Please test and replay.
Hello,
This problem is connected with the fact that the AddWhere method inserts the WHERE statement into the first found SELECT clause.
If you want to use the AddWhere method you should rewrite your query so that it becomes a 'simple' query without the WITH statement, or you can use parameters in the query like
.......
SELECT A.*, B.ItemNo, B.ItemName
FROM GetItemSum A
JOIN _TDAItem B ON A.ItemSeq = B.ItemSeq
WHERE PATINDEX(:param, B.ItemName)>0
UniQuery.ParamByName('param').asString := Item.Text+'%'
This problem is connected with the fact that the AddWhere method inserts the WHERE statement into the first found SELECT clause.
If you want to use the AddWhere method you should rewrite your query so that it becomes a 'simple' query without the WITH statement, or you can use parameters in the query like
.......
SELECT A.*, B.ItemNo, B.ItemName
FROM GetItemSum A
JOIN _TDAItem B ON A.ItemSeq = B.ItemSeq
WHERE PATINDEX(:param, B.ItemName)>0
UniQuery.ParamByName('param').asString := Item.Text+'%'