Sybase SQL: How to check if a value exists before proceeding further?

knowitall

New Member
Hi All,<br />
<br />
I have a really large table and I have a complicated procedure which retreives data for me.<br />
<br />
The table has about 15 columns.<br />
The procedure takes two parameters - a name and a date (both varchar)<br />
<br />
I want to do a check that the name and date exist in the table before the procedure continues with the bulk of the query... I dont want to procedure to execute if either the name or date are invalid.<br />
<br />
What is the quickest way of doing this? without putting too much strain on the DB?<br />
<br />
Thanks.<br />
 

wilco

New Member
If you are using PHP you could run a query like SELECT name FROM table WHERE name = 'John Smith' AND date = '12/3/06', then check how many rows it returned, if it returned 0, it was invalid, if it was 1 or more then it was ok and you can continue with the rest of the query.
 

aznskillz

New Member
add the exists clause you can check for existance before doing what ever you need to do.


for example if you are doing an insert then you can say

insert into table (col1, col2) select "item", "item2" from dual where exists(select * from table where date = "date", name="name")
 
Top