Page 1 of 1

Error in MSQuery.QuoteName=True with Master Detail setup

Posted: Tue 05 Dec 2006 03:19
by siatc1
I have set the following in MSQuery.

1. MSQuery.Options.QuoteName=True
2. MSQuery.Options.QueryRecName=True
3. MSQuery.MasterFields='Title_id'. Note that I'm using Pubs db in MSSQL
4. MSQuery.DetailFields='D.Title_id'
5. MSQuery.SQL='Select * from titleauthor A join titles D on A.title_ID=D.title_ID'

When MSQuery open, it hit error "invalid column D.Title_id". When I check with SQL Profiler, it generate the following statement:

exec sp_executesql N'SELECT * FROM titleauthor A JOIN titles D on A.title_ID=D.title_ID
WHERE [D.title_id] = @P1 ', N'@P1 varchar(6)', 'PS3333'


I believe the correct statement should be :
exec sp_executesql N'SELECT * FROM titleauthor A JOIN titles D on A.title_ID=D.title_ID
WHERE D.[title_id] = @P1 ', N'@P1 varchar(6)', 'PS3333'

Thanks.

Sia

Posted: Tue 05 Dec 2006 13:32
by Jackson
The TCustomDADataSet.Options.QuoteNames property doesn't support field names with table aliases.
Do not use a table alias in the field name or do not use the TCustomDADataSet.Options.QuoteNames = True mode.