If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > check a table to see whether it has nothing in it (was "Help with An SQL statement!")

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-06, 15:25
lucyg_2000 lucyg_2000 is offline
Registered User
 
Join Date: Nov 2003
Location: england
Posts: 95
check a table to see whether it has nothing in it (was "Help with An SQL statement!")

i am currently designing a study resource site for a college, as part of this site i have to design a personal calendar for the students to be able to insert diary entries and view them when the time is right.
Here comes my problem.

I need a statement that will check a database table to see whether it has nothing in it. I have a table with 3 fields that contain no data( username, day_id, message. I need my code to check that the teo fields username and day_id have no data in them. I need this so that i can insert data into that record when these two fields are empty and update the fields when there is data in them.

Sorry for the longwinded message but i have been fussing over this all day and it has got more complicated by the hour.
Reply With Quote
  #2 (permalink)  
Old 02-09-06, 20:21
stanislav.ondac stanislav.ondac is offline
Registered User
 
Join Date: Aug 2005
Posts: 140
Im not sure if this is what you want:

select count(*) from tablename where
username is not null and day_id is not null;
Reply With Quote
  #3 (permalink)  
Old 02-09-06, 20:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
anyone who writes "An SQL statement!" instead of "A SQL statement!" surely deserves a reply

under which circumstances will you find a row where both username and day_id are empty but message isn't? whose message would it be, and for which day?

perhaps if you would kindly show us the CREATE TABLE statement that you used to create the table?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 02-10-06, 06:56
lucyg_2000 lucyg_2000 is offline
Registered User
 
Join Date: Nov 2003
Location: england
Posts: 95
Quote:
Originally Posted by r937
anyone who writes "An SQL statement!" instead of "A SQL statement!" surely deserves a reply

under which circumstances will you find a row where both username and day_id are empty but message isn't? whose message would it be, and for which day?

perhaps if you would kindly show us the CREATE TABLE statement that you used to create the table?
Basically, i wasnt searching the message field because the contents of it are irrelivant. I am running a check as to whether a record is in the database for that username and that day. Example username :gr203 example day_id: 1(monday)
The check is necessary as it determines whether i need to run an insert or update statement. I cannot have two entries in the table for the same username and day hence if both are null then the entry does not already exist so insert the data, else there is already data for that entry so update the specified record.
Thankyou both for your replies so far.
Reply With Quote
  #5 (permalink)  
Old 02-10-06, 07:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
my point is: if the given user has no entry for the given day, there will not be a row with NULL in those two columns, there won't be a row at all!!

see the difference?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On