Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Compact Edition ISNULL(sth, ' ') returns a boolean value?

I have an Accounts table with columns name, password and email. They are all type nvarchar. I wrote a query like

SELECT name, password, ISNULL(email, 'eeee') 
FROM Accounts 
WHERE name = '" + textBox1.Text + "' AND password ='" + textBox2.Text + "'"

I read the email as reader.getString(2) since it is nvarchar.

As I read from the internet, if email is NULL, then it should return eeee. But it says System.boolean can not be translated to System.String.

How can I correct this? Why does it return a boolean value?

like image 671
Ada Avatar asked May 04 '11 23:05

Ada


People also ask

Can Boolean be NULL in SQL?

You should avoid NULL for a boolean. In SQL, you cannot compare NULL with TRUE and FALSE .

What does Isnull return in SQL?

The ISNULL() function returns a specified value if the expression is NULL. If the expression is NOT NULL, this function returns the expression.

Does SQL Server have Boolean?

There is no boolean data type in SQL Server. However, a common option is to use the BIT data type. A BIT data type is used to store bit values from 1 to 64. So, a BIT field can be used for booleans, providing 1 for TRUE and 0 for FALSE.

Is 0 true or false in SQL?

A Boolean table column will contain either string values of "True" and "False" or the numeric equivalent representation, with 0 being false and 1 being true.


1 Answers

According this ISNULL is not implemented in SQL Server CE. I would expect to see a syntax error raised, however.

Workaround: you can use CASE WHEN email IS NULL THEN 'eeee' ELSE email END or COALESCE. Preferably the latter.

Also use parameterised queries. If you don't know why you should, learn.

like image 162
ta.speot.is Avatar answered Sep 20 '22 06:09

ta.speot.is