这是我的SQL代码:
if NOT EXISTS (select * from tblArtist where Artist= 'The Rolling Stones')
INSERT INTO tblArtist (Artist)
Output inserted.ID, 'TRUE' as isNewEntry
Values('The Rolling Stones')
ELSE (Select ID from tblArtist
Where Artist = 'The Rolling Stones');
到目前为止,这是有效的。但如果涉及到else块,它应该返回' FALSE' asNewEntry ...
现在我不能只使用Output关键字,因为我认为它不能与select关键字一起使用。
感谢您的帮助!
答案 0 :(得分:1)
喜欢这个吗?
if NOT EXISTS (select * from tblArtist where Artist= 'The Rolling Stones')
INSERT INTO tblArtist (Artist)
Output inserted.ID, 'TRUE' as isNewEntry
Values('The Rolling Stones')
ELSE (Select ID, 'FALSE' as isNewEntry from tblArtist
Where Artist = 'The Rolling Stones');