?
Solved

freetds / unixodbs: Field alias in SQL not working

Posted on 2008-11-04
3
Medium Priority
?
1,048 Views
Last Modified: 2013-12-13
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.
0
Comment
Question by:projectweb
  • 2
3 Comments
 
LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 100 total points
ID: 22882489
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
 

Author Comment

by:projectweb
ID: 22882610
:-)

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

Accepted Solution

by:
projectweb earned 0 total points
ID: 22884881
I found a workaround myself...

The workaround is

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

Where the cast funtion is the solution
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month16 days, 16 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question