Questions tagged [ifnull]

This tag refers to the process of determining whether or not a particular object is null, and then running certain code based off of that condition.

Use this tag for questions related to running certain code depending on whether or not one or more objects is null.

161 questions
4
votes
1 answer

if(null) is being executed in a specific computer compiling with clang++

I have a large code that we were using for a long time in our team. But its several weeks that there is a problem with it when it is compiled on my machine. The code is cross compiled for an Intel Atom CPU and ran on an specific machine. When it is…
Sheric
  • 416
  • 2
  • 16
4
votes
1 answer

Find the min and max date for a record across multiple tables

I have 3 tables: file_list => list of all files on web server stats_web => number of pageviews from public web stats_reg => number of pageviews from "registered users" I have the schema and some sample data on…
StefWill
  • 353
  • 1
  • 3
  • 13
3
votes
1 answer

Why do MySQL 8 IF and IFNULL return a BLOB result when testing a variable with value NULL?

Note: I have moved the essence of this question to here having learned some of what is happening but still wanting to understand. (In essence, ISNULL and COALESCE behave unusually when a variable is either undefined or has been set to NULL before…
Mike Blyth
  • 4,158
  • 4
  • 30
  • 41
3
votes
1 answer

IFNULL() Equivalent in PostgreSQL

I am working on a project of migrating from MySQL to PostgreSQL, some function can't works well in PostgreSQL like IFNULL function. Some tutorials say that in PostgreSQL we can use NULLIF to handle it. When I try I get an issue "argument of NOT…
Ugy Astro
  • 357
  • 3
  • 6
  • 16
3
votes
1 answer

failed to change '' to null for datetime in mysql stored procedure

i wrote the stored procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_create_new_task`( IN _taskName VARCHAR(30), IN _description VARCHAR(500), IN _startDate DATETIME, IN _endDate DATETIME, IN _lacation …
Gil Hadad
  • 307
  • 1
  • 4
  • 12
3
votes
3 answers

Storing private message 'body' field in separate table for speed gain

I have a private messaging system for my users that I've created in php with a mysql backend. The system deletes old messages but generally holds over 500,000 messages. Currently all of the data is included in one table: message_table message_id…
RebDev
  • 335
  • 1
  • 5
  • 13
3
votes
1 answer

doctrine2 ifnull

hi is there in doctrine2 ifnull? i need to use... how to? SELECT * FROM `apns_task_message` ORDER BY IFNULL( `sent_at` , NOW( ) ) , `priority` DESC , `position` ASC how convert this sql into doctrine? $qb =…
Sergey Gerdel
  • 31
  • 1
  • 5
2
votes
3 answers

IFNULL in Symfony2 Doctrine query builder

How is the IFNULL of SQL implemented in Symfony2 Doctrine Query Builder? Let's say I have this query: select * from ticket order by IFNULL(modified_date, '2000-01-01') DESC, created_date DESC I have this DQL: $this->qb->select("t, c.name") …
ArVan
  • 4,225
  • 8
  • 36
  • 58
2
votes
1 answer

MySQL – Advanced query based on if null and join

I am trying to query several tables with one query based on the values of the joined table. SELECT a.id,a.name, IFNULL(b.imageurl, 'default image url') AS 'imageurl', IFNULL(b.imagecategory, '34') AS 'imagecategory', IFNULL(b.imagetype, 't') AS…
chrismaaz
  • 127
  • 4
  • 12
2
votes
1 answer

MongoDB conditional (sum if exists, else zero)

I am trying to sum across a field within an aggregate pipeline where the field may not exist. Otherwise, the return should be zero. This is my code so far: admits = [ {'$match': {'meta.State': item['state'],'meta.County': item['county'],…
OJT
  • 887
  • 1
  • 10
  • 26
2
votes
2 answers

Postgres convert empty string to NULL

I run a Postgres database and would like to convert empty string into NULL. The following snipped should do this with all columns, but it isn't working. SELECT * FROM schema.table NULLIF(columnname,''); The error message is: ERROR: syntax error at…
Michael
  • 219
  • 2
  • 10
2
votes
4 answers

JOIN WHEN NULL (mysql)

I want to join 2 tables, (table A and table B). If table B is NULL, using 0 instead. is that possible to query this in mysql? Suppose: Table A: id regionID 123 1 456 2 789 3 Table…
hnandarusdy
  • 412
  • 5
  • 19
2
votes
2 answers

How do I use IFNULL with window function in MySQL

How do I use ifnull with a window function? Let's say I have this query result below, lag1 is just the budget column shifted down using the window function, because of that, the value is null. But I want to replace that null with a zero so I can…
Lena
  • 338
  • 3
  • 15
2
votes
2 answers

IFNull in MySQL

I am new to SQL and I am trying to create a calculated field using a set of columns. However, some of those values may be NULL. If they are NULL, I don't want the calculated field to return a NULL result but instead set some arbitrary value. Here is…
Spencer
  • 21,348
  • 34
  • 85
  • 121
2
votes
2 answers

having condition on result of a subquery in mysql

i am trying to run a query like this SELECT a, b , c, (SELECT INNULL(x,y)) as mycol WHERE mycol < 400 ; BUt it gives the error #1054 - Unknown column 'mycol' in 'where clause' What would be the right way to do this? Thanks.
naiquevin
  • 7,588
  • 12
  • 53
  • 62
1
2
3
10 11