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
1
vote
1 answer

How to use $ifNull in $match stage in MongoDB

I added a condition like below to an aggregation in mongodb. "$match" : { $ifNull: ["$startDate", "$createdAt"] : {"$gte": ISODate("2018-06-01 10:03:46.000Z"), "$lte": ISODate("2018-06-29 10:03:46.000Z")} } When I…
HieuBui
  • 37
  • 1
  • 6
1
vote
0 answers

MYSQL stored procedure, if statement, ifnull

I'm trying to create a stored procedure with mysql. The idea is not check if the first request is empty or not, and do it if it's not, or do the second one if the first is empty. My code, symplified version. DELIMITER // CREATE PROCEDURE…
Tycho
  • 33
  • 6
1
vote
1 answer

cakePHP 3 Query ifnull

I wonder what would be the best way to prevent null results in a ResultSet. I'm on cake 3.5.13 and I'm using cases, like: private function addCase($isforeign, $source) { $query = $this->Sales->find(); return $query->newExpr() …
Seb
  • 145
  • 1
  • 13
1
vote
1 answer

How to return value if there is no row?

I reading data from table through Qml + JS and I need to have 100 return is the query doesn't found data: SELECT (CASE WHEN pourcenthour < pourcentcycle AND pourcenthour < pourcentmonth THEN pourcenthour WHEN pourcentcycle <…
Philippe
  • 25
  • 1
  • 7
1
vote
1 answer

sql select condition, if col1 empty check on col2

How could I achieve the following in SQL. (I have trouble with the checking if col1 is empty, check if col2 is "confirmed") select data from table1 where col1 = "true" or (if col1 is empty, check col2 = "confirmed"). (the value to check for col1…
jmmom
  • 313
  • 3
  • 7
1
vote
2 answers

SQL IFNULL with condition and write CSV

I have a table with null values and datatypes for all columns are integer/real. I'd like to write 'no data' if the field is null when writing the data to csv. Here is the testTable. id test1 test2 test3 ------ ------ ------ ------ 1 1 …
monty_bean
  • 494
  • 5
  • 25
1
vote
3 answers

Can IFNULL() return a string where the column value is int, using MySQL?

My query select cname, count(screening_occapancy.idclient) as 'Count' from client, screening_occapancy where client.client_no = screening_occapancy.idclient group by cname returns the following: Name Count Name1 2 Name2 …
Gilzy
  • 103
  • 1
  • 1
  • 4
1
vote
1 answer

MongoDb cannot get result from $ifNull

Am using the following script to update quotes as escaped characters in strings that are held in a 4 String array and am unable to get the $ifnull to work. Have tried various forms and the latest is: var myCursor = db.collection.Fence.find( {…
Roddy
  • 2,018
  • 3
  • 16
  • 21
1
vote
1 answer

How do I query MongoDB from PHP with IFNULL() expression inside WHERE?

I use this query to query NULL values as "0": select * from myTable where IFNULL(field_id, 0) = 0 How do I achieve the same in MongoDB using PHP? My code: /** * @var MongoDB */ $db = $this->getMongoDbHandler(); /** * @var MongoCollection …
temuri
  • 2,767
  • 5
  • 41
  • 63
1
vote
3 answers

Concat inside IFNULL

I have a statement SELECT CONCAT(lastName, ' ', firstName, '', IFNULL(middleName, '')) which works fine, it gives me all names whether there's a middle name or not. My problem is that I don't want to include the empty space after the first name for…
Cody Harness
  • 1,116
  • 3
  • 18
  • 37
1
vote
1 answer

Single query for several selects -even if one select returns empty

I need to make several select statements to get simple data (only one row containing one or several fields for each select). Simplified example: select name, price from article where id=125 select log, email from user where uid=241 I want to…
fpierrat
  • 739
  • 7
  • 25
1
vote
1 answer

How to make a function use CASE and IFNULL in postgreSQL?

can you tell me how to use CASE and IFNULL in postgre? i'm migrating from sql to postgreSQL, and i want to make a function with this syntax : SELECT a.furniture_id, a.furniture_brand, a.furniture_cost, CASE WHEN furniture_id = f_id THEN…
1
vote
2 answers

How to insert an alternative value from an old table into a new table IF NULL.

I have this old_table. ID: First_name: Last_name: Age: 1 Christian Johnson 25 2 John Christiansen 21 3 Peterson 23 and this new_table I just created, by this piece of code: CREATE…
1
vote
1 answer

Having trouble with an IFNULL in a mySQL WHERE clause

Before anyone says, I have searched through for a suitable answer for my issue but cannot find anything specific enough so I thought I'd ask it. Basically I am trying to select a bunch of data for a report of people who have made loan applications…
mjemerson
  • 55
  • 5
1
vote
2 answers

IFNULL not working like I want to

I have two DATE-fields (PublishFrom, PublishTo) that are nullable. I am trying to get the records with this query: SELECT * FROM tblNews WHERE Publish = 1 AND IFNULL(PublishFrom, CURDATE() - INTERVAL 1 DAY) <= "2015-03-13" AND…
bflydesign
  • 483
  • 8
  • 22