473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

query that will return null values to 0

i'm using mySQL as my backend to my program. i know this is not VB.NET
anymore but i don't know how to do it. i have a query that will calculate if
it satisfies the condition. it goes like this:

SELECT
(tblseedsubsidy.NoOfBags)
FROM
agri.tbltrcclient
INNER JOIN agri.tblseedsubsidy
ON (tbltrcclient.ClientID = tblseedsubsidy.ClientID)
INNER JOIN agri.tblinventory
ON (tblseedsubsidy.SeedID = tblinventory.SeedID)
WHERE (tblseedsubsidy.CoOwner = '1'
AND tbltrcclient.TypeofSeed = 'Corn')
HAVING (sum(tblseedsubsidy.NoOfBags) /2);

but every time it doesn't satisfy the condition where CoOwner must be equal
to '1' it returns a null value. how can i convert the null value into 0?

if anyone has any idea on how to do it i would really appreciate it. thanks.

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200805/1

Jun 27 '08 #1
7 2164
Enrico as you said, nothing to do with VB, however in SQL script it is

(..............Or tblseedsubsidy.CoOwner Is Null)

Cor

"enrico via DotNetMonster.com" <u41845@uweschreef in bericht
news:83ae12e7b023d@uwe...
i'm using mySQL as my backend to my program. i know this is not VB.NET
anymore but i don't know how to do it. i have a query that will calculate
if
it satisfies the condition. it goes like this:

SELECT
(tblseedsubsidy.NoOfBags)
FROM
agri.tbltrcclient
INNER JOIN agri.tblseedsubsidy
ON (tbltrcclient.ClientID = tblseedsubsidy.ClientID)
INNER JOIN agri.tblinventory
ON (tblseedsubsidy.SeedID = tblinventory.SeedID)
WHERE (tblseedsubsidy.CoOwner = '1'
AND tbltrcclient.TypeofSeed = 'Corn')
HAVING (sum(tblseedsubsidy.NoOfBags) /2);

but every time it doesn't satisfy the condition where CoOwner must be
equal
to '1' it returns a null value. how can i convert the null value into 0?

if anyone has any idea on how to do it i would really appreciate it.
thanks.

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200805/1
Jun 27 '08 #2
Hello Enrico ,

this should do the trick

SELECT
ISNULL(tblseedsubsidy.NoOfBags,0) AS NoOfBags
FROM
agri.tbltrcclient
INNER JOIN agri.tblseedsubsidy
ON (tbltrcclient.ClientID = tblseedsubsidy.ClientID)
INNER JOIN agri.tblinventory
ON (tblseedsubsidy.SeedID = tblinventory.SeedID)
WHERE (tblseedsubsidy.CoOwner = '1'
AND tbltrcclient.TypeofSeed = 'Corn')
HAVING (sum(tblseedsubsidy.NoOfBags) /2);
As you did not provide the data structure i asume that
tblseedsubsidy.NoOfBags is a numericdatatype field otherwise change above
to
SELECT
ISNULL(tblseedsubsidy.NoOfBags,'0') AS NoOfBags
....................................

HTH

Michel Posseth

"enrico via DotNetMonster.com" <u41845@uweschreef in bericht
news:83ae12e7b023d@uwe...
i'm using mySQL as my backend to my program. i know this is not VB.NET
anymore but i don't know how to do it. i have a query that will calculate
if
it satisfies the condition. it goes like this:

SELECT
(tblseedsubsidy.NoOfBags)
FROM
agri.tbltrcclient
INNER JOIN agri.tblseedsubsidy
ON (tbltrcclient.ClientID = tblseedsubsidy.ClientID)
INNER JOIN agri.tblinventory
ON (tblseedsubsidy.SeedID = tblinventory.SeedID)
WHERE (tblseedsubsidy.CoOwner = '1'
AND tbltrcclient.TypeofSeed = 'Corn')
HAVING (sum(tblseedsubsidy.NoOfBags) /2);

but every time it doesn't satisfy the condition where CoOwner must be
equal
to '1' it returns a null value. how can i convert the null value into 0?

if anyone has any idea on how to do it i would really appreciate it.
thanks.

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200805/1

Jun 27 '08 #3
it still doesn't work. it prompts an error something like "Incorrect
parameter count...". is it possible that it doesn't recognize the isnull
statement?

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200805/1

Jun 27 '08 #4
enrico via DotNetMonster.com wrote:
it still doesn't work. it prompts an error something like "Incorrect
parameter count...". is it possible that it doesn't recognize the
isnull statement?
What does
HAVING (sum(tblseedsubsidy.NoOfBags) /2)
mean?
Jun 27 '08 #5
i use sqlyog to test my query. i just drop and drag my fields and put some
criteria on what i want my query is to be, and it gave a "having" statement.
i didn't care at all because my query worked.

--
Message posted via http://www.dotnetmonster.com

Jun 27 '08 #6
enrico via DotNetMonster.com wrote:
i use sqlyog to test my query. i just drop and drag my fields and put
some criteria on what i want my query is to be, and it gave a
"having" statement. i didn't care at all because my query worked.
I just thought it was unusual to say
HAVING (sum(tblseedsubsidy.NoOfBags) /2)

Normally criteria include some sort of comparision, such as
sum(tblseedsubsidy.NoOfBags) /2 0

Jun 27 '08 #7
1000 times sorry :-) i missed this
"i'm using mySQL as..........."

The SQL i Showed that would have solved the problem is in MSSQL dialect

MYSQL however uses a slightly different dialect

the solution for MYSQL would be
SELECT
IFNULL(tblseedsubsidy.NoOfBags,0) AS NoOfBags
FROM
agri.tbltrcclient
INNER JOIN agri.tblseedsubsidy
ON (tbltrcclient.ClientID = tblseedsubsidy.ClientID)
INNER JOIN agri.tblinventory
ON (tblseedsubsidy.SeedID = tblinventory.SeedID)
WHERE (tblseedsubsidy.CoOwner = '1'
AND tbltrcclient.TypeofSeed = 'Corn')
HAVING (sum(tblseedsubsidy.NoOfBags) /2);

HTH

And again sorry for missing the MYSQL part

Regards

Michel Posseth [MCP]



"enrico via DotNetMonster.com" wrote:
it still doesn't work. it prompts an error something like "Incorrect
parameter count...". is it possible that it doesn't recognize the isnull
statement?

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200805/1

Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bob Bedford | last post by:
I've a table on mysql: code1 tinyint, code2 tinyint, notcode1 varchar(20),notcode2 varchar(20),label I do have some records: values(1,null,null,null,'text1');...
0
by: Ralph Guzman | last post by:
TASK: I have to generate a report with all categories, subcategories and products in database. PROBLEM: I want to write one query that will return: 1. category 2. subcategory: determined by...
1
by: per | last post by:
im not very good at sql but need to query the database to use in my programming script. if the database is just like this id name parent_id 1 A ...
22
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20...
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
3
by: brendan_gallagher_2001 | last post by:
Hi, I have a view(A) and I am trying to do a join on another table (B) to include only rows where date values in view A is greater than in table B. I also want the view to pick up rows in viewA...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
5
by: DeanL | last post by:
Hi all, I'm trying to set up a query that runs from a command button on a form (simple enough so far), what I want the query to do is take values from the fields on the form (seven fields in...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.