Board index » delphi » SQL Macro works against 6.5, fails against 7

SQL Macro works against 6.5, fails against 7

The following  macro works in MS SQL 6.5 but not in 7.0
    query.add('select db_name() as dbname');
    query.active := true;
    dbname := query.fieldbyname('dbname').asstring

in 7.0 the field count is zero so Fields[0] will not work and 'dbname'
is not seen as a valid field name.
A direct ODBC call using ODBCExpress for example works fine.  Does
anyone have a solution to
this?

Using Delphi 4 Client/Server with updates, MS SQL 6.5, 7.0, BDE 5.01.

 

Re:SQL Macro works against 6.5, fails against 7


Replace the statement by:
select convert (char (50), db_name()) as dbname

SQL 7 returns a 'nvarchar'. It looks like Delphi doesn't receive this:
we had the same problem: we had to replace
'select Fld=@@ServerName'
 with
'select Fld=convert (char(50), @@ServerName)'

Other Threads