freetds / unixodbs: Field alias in SQL not working

I have a FreeBSD dedicated server with: Apache 2.0, PHP 5.2, unixODBC and FreeTDS Version 8.0 (0.63) configured that can perfectly connect to a MS SQL Server 2005.
(I work with odbc_connect, odbc_result and so on)

Problem description:

A simple SQL statement like this works fine:
$SQL="SELECT TOP 1 IDPRODUCT FROM PRODUCTS WHERE IDPRODUCT > 5000;"

BUT a bit more complex SQL statement like:
$SQL="SELECT PRODUCTNAME AS NAME FROM PRODUCTS WHERE IDPRODUCTS > 5000;"

Gives me an error like this:
Warning: odbc_result() [function.odbc-result]: Field NAME not found in /home/babyshop/public_html/shop.php on line 198

What is wrong?

Do I use the wrong FreeTDS driver or what could this be?

Thx for your help.
projectwebAsked:
Who is Participating?
 
projectwebConnect With a Mentor Author Commented:
I found a workaround myself...

The workaround is

SELECT (PRODUCTNAME AS NTEXT) AS NAME FROM .....

Where the cast funtion is the solution
0
 
Roger BaklundConnect With a Mentor Commented:
This is probably not the reason for the error, but I noticed in the first query you have

WHERE IDPRODUCT > 5000

and in the second query:

WHERE IDPRODUCTS > 5000

Remove the S.

Are you sure there is a column named PRODUCTNAME?
0
 
projectwebAuthor Commented:
:-)

That was just a typo.
Sorry for that. (good try, but i'm afraid it isn't that simple)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.