By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,403 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,403 IT Pros & Developers. It's quick & easy.

what will be the function for this

P: n/a
Hi,
I am unable to find the proper function to get the following.
I have 2 cells with date and time in a table. I have to check if the
combination of given date & time exists in the table before a new record is
inserted.
Any idea what function will do this?

Ashok.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello!
I am unable to find the proper function to get the following.
I have 2 cells with date and time in a table. I have to check if the
combination of given date & time exists in the table before a new record is
inserted.
Any idea what function will do this?


I assume you are speaking about a DB table.
Try to check whether the resultset you get when querying the DB with
SELECT * FROM myTable WHERE (date = given_date) AND (time = given_time);

If the resultset is empty there is no such record.

Perhaps you want to use a PRIMARY KEY(date, time).

Greets,
Hero Wanders
Jul 17 '05 #2

P: n/a
Hero Wanders wrote:
Hello!
I am unable to find the proper function to get the following.
I have 2 cells with date and time in a table. I have to check if the
combination of given date & time exists in the table before a new record is
inserted.
Any idea what function will do this?


I assume you are speaking about a DB table.
Try to check whether the resultset you get when querying the DB with
SELECT * FROM myTable WHERE (date = given_date) AND (time = given_time);

If the resultset is empty there is no such record.


If it's MySQL, "REPLACE INTO" and proper keys will do it
automatically.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

Jul 17 '05 #3

P: n/a
NC
Ashok wrote:

I have 2 cells with date and time in a table.
Why? You should have ONE field of DATEIME type.
I have to check if the combination of given date & time exists
in the table before a new record is inserted.


You absolutely don't have to check it. Create a unique
index on the DATETIME field suggested above (or, if you
insist on keeping your awkward two-field combination,
a single index on both date and time fields). Then you
can INSERT all you want, no duplicates will be allowed;
include the IGNORE keyword, if you want to suppress error
messages.

Cheers,
NC

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.