Solutions for INSERT OR UPDATE on SQL Server
https://stackoverflow.com/questions/108403/solutions-for-insert-or-update-on-sql-server/243670#243670
http://blog.sina.com.cn/s/blog_4f0322c501015jqp.html
MERGE ProjectInfoAppInfoes WITH ( HOLDLOCK ) AS target
USING (
VALUES
( '-1' ,
'-1'
) ) AS source ( ProjectInfo_Id, AppInfo_Id )
ON target.ProjectInfo_Id = 7
WHEN MATCHED THEN
UPDATE SET ProjectInfo_Id = source.ProjectInfo_Id ,
AppInfo_Id = source.AppInfo_Id
WHEN NOT MATCHED THEN
INSERT ( ProjectInfo_Id ,
AppInfo_Id
)
VALUES ( source.ProjectInfo_Id ,
source.AppInfo_Id
);