Solved

Please help me with the query

Posted on 2011-03-09
6
276 Views
Last Modified: 2012-08-13
let say you run the query
Select * from tblMain

if you have the data you will get result:
num   name     zip
1      Steven 91356
2     Leonad 94875
and so on...
how about if you do not have anything you will get this
num   name     zip
how to modify the query and get just something like this:
0
0
Comment
Question by:rfedorov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9
ID: 35089458
That's not how queries work.  They return records if they exist, not if they don't.  Can you tell us what you are trying to accomplish with this "zero" record?
0
 
LVL 41

Expert Comment

by:Sharath
ID: 35089494
Try this.
Select num,name,zip from tblMain
union all
select 0,null,null where not exists (select 1 from tblMain)

Open in new window

0
 

Author Comment

by:rfedorov
ID: 35095788
Thank you, guys.
To ArmenStein:i need to get the count of records even if there is no records. ---in this case is Zero is my result. I need the count to add to one more query results to get the final number
To: Sharath_123: i am getting the error message
Syntax error(missing operator) in query exression 'null where not exists (select 1 from tblMain)
'
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 41

Expert Comment

by:Sharath
ID: 35102035
Check this
Select num,name,zip from tblMain
union 
select 0,null,null from tblMain where not exists (select 1 from tblMain)

Open in new window

0
 

Author Comment

by:rfedorov
ID: 35109940
thank you, it did not give me the error, but it does not give me the zero
i added the extra field Date
what i want, i think it make more sense, show me * from the table where date is not todays

and it stll gives me just a header:
num name zip Date

and i want like that
num name zip Date
0
is this possible???
Select num,name,zip,Date from tblMain where Date =format(now,"mm/dd/yyyy")
union 
select 0,null,null,null from tblMain where not exists (select 1 from tblMain)

Open in new window

0
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 35113342
You have to add the WHERE condition in the sub query also.
Select num,name,zip,Date from tblMain where Date =format(now,"mm/dd/yyyy")
union 
select 0,null,null,null from tblMain where not exists (select 1 from tblMain where Date =format(now,"mm/dd/yyyy"))

Open in new window

0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question