我有一个GenreTable:
我有一个“CombinedTable”:
我有一个触发器:
ALTER TRIGGER [dbo].[trgAfterUpdate] on [dbo].[Genre]
AFTER UPDATE
AS
INSERT INTO [dbo].[CombinedTags]([Combined])
SELECT TOP 1 PodcastGenre
FROM Genre
ORDER BY rowID DESC
我正在尝试触发器,以便当一个值在“GenreTable”[(MovieGenre),(MusicGenre),(PodcastGenre)]中的列的以太符号时
它将“RowID”插入“CombinedTable”的“ForeignRowID”列中,并将“value”插入“GenreTable”列的以太列中,插入“Combined”。谢谢你的帮助。
答案 0 :(得分:0)
AS
declare @rowid int
declare @insfld varchar(max)
select @rowid = rowid from inserted
-- assume that only one field has value....
select @insfld = case when moviegenre is not null then moviegenre
when musicgenre is not null then musicgenre
else podcastgenre end whichone
from inserted
INSERT INTO [dbo].[CombinedTags]([Combined], foreignkeyid) values
( @insfld,@rowid)