Friday, February 24, 2012

Insert Query

how can i do an insert into a table, only if the record doesnt exist,
ie insert into tb1
values ('my name', 'myage', 'mynumber')Peter
IF NOT EXISTS (SELECT * FROM Table WHERE...)
INSERT here
ELSE
......
"Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
news:8A2461A6-CCA2-4B19-B041-338582E5AC10@.microsoft.com...
> how can i do an insert into a table, only if the record doesnt exist,
> ie insert into tb1
> values ('my name', 'myage', 'mynumber')
>|||Or in an inline query like:
insert into tb1
SELECT 'my name', 'myage', 'mynumber'
WHERE NOT EXISTS
(SELECT * FORM tb1 Where col1 = 'my name' AND
colb = 'myage' AND
colc = 'mynumber'
)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--

No comments:

Post a Comment