troubleshooting Question

MS SQL insert record with static value if if does not already exist

Avatar of siacom
siacomFlag for Australia asked on
DatabasesMicrosoft SQL Server 2005SQL
6 Comments1 Solution1824 ViewsLast Modified:
I want to insert a record into an SQL table only IF the value for that ID does not exist.

I have 4 fields.
listid, cusid, userid, Company

in one statement I want to:

INSERT values (cusid=null, userid=25, company=null)
  IF ((SELECT userid=25 AND comapny = NULL) = TRUE)

I hope I'm making sense :)

I know that the above is completly wrong syntax, but I thought it might share light on what I want to achive.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
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 1 Answer and 6 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