Re: NULL to 0 result

From: Date: Wed, 15 Dec 2010 10:42:15 +0000
Subject: Re: NULL to 0 result
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-47542@lists.php.net to get a copy of this message
On 14 December 2010 21:53, Ron Piggott <ron.piggott@actsministries.org> wrote: > > What change is needed to this query so if “currently_in_rssâ€� is NULL it will be assigned a > value of 0 > > SELECT reference, COUNT(referencek,æq¸ñᨠ> !ü4ì­�) AS currently_in_rss FROM ministry_profiles WHERE > rss_feed_include = 1 GROUP BY > rss_feed_include > > Ron Doesn't that query give you an error saying that reference isn't in the GROUP BY clause? I use MS SQL, so the wording my be different but it would be along the lines of ... For the SQL statement : SELECT POH_Contract, COUNT(POH_Contract) FROM [BV-CLUSTER-SQL].Contracts.dbo.POP_Header WHERE POH_Status = 1 GROUP BY POH_Status Column 'bv-cluster-sql.contracts.dbo.pop_header.POH_CONTRACT' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. So, fixing the query ... SELECT POH_Contract, COUNT(POH_Contract) FROM [BV-CLUSTER-SQL].Contracts.dbo.POP_Header WHERE POH_Status = 1 GROUP BY POH_Status, POH_Contract now works. So, your query may need to be SELECT reference, COUNT(reference) AS currently_in_rss FROM ministry_profiles WHERE rss_feed_include = 1 GROUP BY rss_feed_include, reference Normally COUNT() will count NULLs, but as you are grouping by the counted column, nulls would be in their own row. Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.db (#47542) next »