_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › Output

Contents



--DROP TABLE dbo.Employees
CREATE TABLE dbo.Employees
(
EmployeeID INT NOT NULL IDENTITY(1, 1),
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Status VARCHAR(20) DEFAULT 'Single'
) 

INSERT INTO dbo.Employees ( FirstName, LastName )
OUTPUT INSERTED.*
SELECT 'Susan', 'Kelley'
/*
EmployeeID  FirstName   LastName    Status
----------- ----------- ----------- --------------------
1           Susan       Kelley      Single
*/
GO

DECLARE @Employees TABLE 
(
	DeletedEmployeeID INT 
,	DeletedFirstName VARCHAR(50)
,	DeletedLastName VARCHAR(50)
,	InsertedLastName VARCHAR(50)
,	DeletedStatus VARCHAR(20)
,	DeletedDT DATETIME
) 

UPDATE dbo.Employees
SET LastName = 'Jones', Status = 'Married'
OUTPUT 
	DELETED.EmployeeID
,	DELETED.FirstName
,	DELETED.LastName
,	INSERTED.LastName -- !!!!!!!!!
,	DELETED.Status
,	GETDATE()
INTO @Employees
WHERE EmployeeID = 1

SELECT * FROM @Employees


create table #temp(seq int)

declare @out table
(
    seq int
)

insert @out
select seq
from (
    insert #temp 
    output inserted.*
    select number from master.dbo.spt_values
) t (seq)

select * from @out

insert audit(action, insert_id, insert_pw, delete_id, delete_pw)
select action, insert_id, insert_pw, delete_id, delete_pw
from (
	merge --top (100) percent 
	target_table a using source_table b
	on a.id = b.id 
	when matched then 
		update set 
			a.id = b.id
		,	a.pw = b.pw
	when not matched by target then
		insert values (id, pw)
	when not matched by source then
		delete
	output $action, inserted.*, deleted.*
) t (action, insert_id, insert_pw, delete_id, delete_pw);
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

企┯ 磯Μ螳 蠍磯 企 蠍磯る 蟆 蠏 豌願 襦 伎朱 企. (D. 殊)