Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"IF EXISTS" alternate in a stored procedure

Status
Not open for further replies.

PawelTru

Programmer
Jul 18, 2002
24
US
I am new to Pervasive and I am trying to create stored procedure which inserts data in to a table. The stored procedure has to check if a record already exists and if it does then it just updates the record on the other hand if the record does not exists it inserts the info into the table

In MSSQL I can type IF EXISTS(Select * from [table name] where [something = something]

This does not work in Pervasive.

How do I work around it.

Thanks
 
Try to using your IF EXITS(select...) in the WHERE condition
of your statement (not in the SELECT) . PSQL doesn't support the most functions in the SELECT part.
 
What I am trying to achieve is to check if something exist if it does it updates the information and if it does not it inserts the new information, so I want to create something like this

If exists (<select statemetn) then
update <whatever>
else
insert <whatever>
end if

In Microsoft SQLServer that is easy in stored porcedure how do I get it in Pervasive

Thanks
 
The easiest way that I know of to do this is something like:

Update MyFile Set MyValues = 'Whatever';

IF @@ROWCOUNT = 0 THEN
INSERT INTO MyFile (A,B,C) Values(1,'X','Whatever');
END IF;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top