473,386 Members | 1,674 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,386 software developers and data experts.

SQL Display Null Values

21
Hi,
I am using C# code to retreive values from a table in sequel.
This is done using a join between a table containg values and one using dates.
The problem is that I am unable to retrieve a value for days where there is no value. I would like to return a 'NULL' value or even a ' 0 ' value if no amount is found for that specific date/day.


SELECT COUNT(*) AS Expr1
FROM db.sales_month RIGHT OUTER JOIN
db.sales_dates ON dbo.sales_month.full_date = db.sales_dates.[Date] AND db.sales_month.full_date = db.sales_dates.[Date]
WHERE (db.sales_month.prod_name = 'Chairs') AND
GROUP BY db.sales_month.full_date
ORDER BY db.sales_month.full_date
May 7 '07 #1
6 6840
scripto
143 100+
SELECT COUNT(*) AS Expr1
FROM db.sales_month RIGHT OUTER JOIN
db.sales_dates ON (dbo.sales_month.full_date = db.sales_dates.[Date] AND
db.sales_month.prod_name = 'Chairs')
GROUP BY db.sales_month.full_date
ORDER BY db.sales_month.full_date
May 7 '07 #2
NiteshR
21
SELECT COUNT(*) AS Expr1
FROM db.sales_month RIGHT OUTER JOIN
db.sales_dates ON (dbo.sales_month.full_date = db.sales_dates.[Date] AND
db.sales_month.prod_name = 'Chairs')
GROUP BY db.sales_month.full_date
ORDER BY db.sales_month.full_date
Thanks for the help.
I used the code you sent me, but it still doesn't output all the null values.
The only output are those which are greater than 0.
Is there anything else i can use to do this? eg. a if..then statement in sql
May 8 '07 #3
scripto
143 100+
if there is no entry for a specific day or days in the db.sales_dates table then you will not get a null value or a 0. You would need to create another join on another table (like tblSeptember) where those dates exist, then you can get all the nulls for dates in September.
May 8 '07 #4
NiteshR
21
if there is no entry for a specific day or days in the db.sales_dates table then you will not get a null value or a 0. You would need to create another join on another table (like tblSeptember) where those dates exist, then you can get all the nulls for dates in September.
Ok, I understand what you mean by this.
The only way i think i can overcome this is by inserting a if..else statement within the sql query, maybe by creating a stored procedure.

Any ideas on this?

Thanks.
May 9 '07 #5
scripto
143 100+
well, if your db.sales_month table has the dates you need, then try a Left Outer join. Let me/us know how it goes.
May 9 '07 #6
NiteshR
21
well, if your db.sales_month table has the dates you need, then try a Left Outer join. Let me/us know how it goes.
hi,
i joined the two tables using a right outer join and insert those values into a new table.
i then joined that table using a right outer join to give me the output i required.

thanks.
May 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tristan Miller | last post by:
Greetings. I am trying to write a function which toggles the display of a certain class of <div> elements in an HTML page. The CSS file initially sets some classes to "display: none", and...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
18
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those...
4
by: dennis.joseph | last post by:
Hello Everyone, I have scoured through a million messages (ok...thats a bit exaggerated) but I just cannot figure out how to display null values in a query. I have tried Nz, IIF, Count(*) but it...
8
by: sweetpotatop | last post by:
Hello, I would like to query the top 5 best companies' sales (total sales), then total the rest, what is the quickest and effective SQL to query it? Thanks in advance
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
1
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
2
ak1dnar
by: ak1dnar | last post by:
CREATE TABLE `products` ( `p_id` int(11) NOT NULL, `p_name` varchar(15) default NULL, `p_features` varchar(100) default NULL ) from this table I am going to fetch the records and display...
4
by: Mubs | last post by:
Hi ppl, I am trying to insert records into my database using a form. this works. but after this i would like the records to be displayed onto another page.. the database gets updated but the...
4
by: naveenkongati | last post by:
Hi, I am using Displaytag to populate values on Jsp page using(display:column).If I want to pass two values from this page to next jsp page with href & paramID , i am only getting one value and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.