메모
insert into set... mysql에서만...펌
맘편한넘
2014. 1. 10. 14:27
The SET
way to insert records is not standard SQL. If you need it to use similar sql's for updates and inserts, you should use Stored-Procedures in MS SQL-Server instead, for example:
CREATE Procedure tableInsertUpdate
(
@ID int,
@fil1 int,
@fil2 int,
@IDOut int OUTPUT
)
AS
IF EXISTS(SELECT ID from table WHERE ID=@ID)
BEGIN
UPDATE table SET
fil1 = @fil1
fil2 = @fil2
WHERE ID=@ID
SET @IDOut=null
END
ELSE
BEGIN
INSERT INTO table
(fil1, fil2)
VALUES
(@fil1, @fil2 )
SET @IDOut=scope_identity()
END