tags:

views:

80

answers:

2
SELECT Trainer.id AS idTrainer, surname, lastname, name,  
if(month = '', 'NO',month) as monthT, quarter, halfyear, year, id_Person, photo
FROM Trainer, Person
WHERE Trainer.id_Person = Person.id

if(month = '', 'NO',month) as monthT in phpmyadmin return good or 'no' or month

In a C# returns byte[], but I need return NO if month is empty or else return the month.

My C# code looks like this:

string sql = @" SELECT Trainer.id AS idTrainer, surname, lastname, name,  if(month = '', 'NO',month) as monthT, quarter, halfyear, year, id_Person, photo
                FROM Trainer, Person
                WHERE Trainer.id_Person = Person.id";
using (MySqlConnection connection = ConnectToDataBase.GetConnection())
{
    MySqlCommand command = new MySqlCommand(sql, connection);
    MySqlDataAdapter adapter = new MySqlDataAdapter();

    connection.Open();
    adapter.SelectCommand = command;
}
A: 

I'm no MySql expert but why you don't try to cast?

CAST(if(month = '', 'NO',month) AS VARCHAR) AS monthT

more here: http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html

gsharp
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR) as monthT, quarter, halfyear, year, id_Person, photo ' at line 1
simply denis
this is exception
simply denis
As I said, I'm no MySql expert and I don't have any MySql installed. It was just a hint for you how to solve it... I'm sure you can figure it out how to make it run ;-)
gsharp
i'm use this function, but it does not work
simply denis
+2  A: 

While researching I have found out that there is the bug with VARCHAR using CAST. The solution is to use CHAR instead of VARCHAR.

Proof links:

Using Conversion Functions

Bug #34564 CAST does not accept varchar type

Cast Functions and Operators

Eugene Cheverda