IF NOT EXISTS(SELECT * FROM Employee where code = 'testcode1')
INSERT INTO
Employee(code, fname, lname)
VALUES
('testcode1', 'testfn', testln')
ELSE
RAISERROR (SELECT * FROM Employee where code = 'testcode1', 11, 1)
如果数据已存在于不在网格中的消息中,我如何返回结果?
示例输出
Code fname lname
------------- -------- -----------
tescode1 testfn testln
答案 0 :(得分:0)
你可以将它放在一个消息变量中并提高它。例如:
DECLARE @Message varchar(200)
IF NOT EXISTS(SELECT * FROM Employee where code = 'testcode1')
BEGIN
INSERT INTO
Employee(code, fname, lname)
VALUES
('testcode1', 'testfn', 'testln')
END
ELSE
BEGIN
SELECT @Message = FNAME + ' ' + LNAME FROM Employee where code = 'testcode1'
RAISERROR (@Message, 11, 1)
END