all groups > sql server mseq > october 2003 >
You're in the

sql server mseq

group:

Check table content before insert


Check table content before insert Georges Vautherin
10/24/2003 3:26:07 AM
sql server mseq: Hi,
I have a problem checking the content of a table before inserting a new row.
What I would like is a SQL statement for a web form which does the following:
IF (SELECT aField FROM aTable WHERE aField="astring") is empty then
INSERT INTO aTable (aField ) VALUES ('astring')
END IF
What is the best way of doing this? I am sure it's possible I just don't know how to do it.
Cheers,
Re: Check table content before insert Vishal Parkar
10/24/2003 4:16:20 PM
Georges,

Following T-SQL syntax should work.

IF not exists (SELECT aField FROM aTable WHERE aField='astring')
INSERT INTO aTable (aField ) VALUES ('astring')

--
- Vishal


AddThis Social Bookmark Button