Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 insert/update query

Author  Topic 

quali74
Starting Member

5 Posts

Posted - 2005-07-28 : 11:45:54
hello all,

I am connecting a sql server via PHP.
I would like to write a query that does an insert or update depending on the content of the DB.

The equivalent in Mysql is:
insert into table (id,data1) VALUES ('1','test1') on duplicate key update ('test2')

Does anybody know the syntax?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-07-28 : 12:22:05
this should do it...

update table
set data1 = 'test1'
where id = '1'
if @@rowcount = 0
begin
insert into table(id, data) VALUES ('1','test1')
end



Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -