troubleshooting Question

sql - if exists

Avatar of -Dman100-
-Dman100-Flag for United States of America asked on
ASP.NETMicrosoft SQL Server 2005
5 Comments2 Solutions3371 ViewsLast Modified:
I'm not sure my question will be able to be answered, but if anyone can help, it will be greatly appreciated.

I'm using a webservice to make calls into SalesForce.com API.  We use SalesForce as our CRM system.  SalesForce uses a proprietary version of SQL called SOQL.  It has limitations on joins, aggregates and other functions that regular SQL uses.  One limitation might be the use of the IF EXISTS statement, but I haven't found any documentation that says I can't use it.

I'm trying to do the following:

I want to write a function that checks if a record exists in one of the objects (tables) we have on their system and return true if the record exists and false if the record does not exist.

I want to use the function in an if statement and branch based on the return value of the function
 
If (function returns true) {
     do some processing here...
}
else {
     do some other processing...
}
 
The function would use the 'if exists' in the SOQL query to determine if a record exists in the contact object and return true or false.

IF EXISTS (Select c.Email, c.FirstName, c.HasOptedOutOfEmail, c.LastName from Contact c WHERE email = 'test@test.com')
SELET 1
ElSE
SELECT 2
 

I can't get this to work using SOQL, which might not allow the IF EXISTS statement.  Is there another method to accomplish the same thing?  Any code samples, examples would be helpful.
 
Thanks for any help.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros