如何在存储过程中使用局部变量? [英] How to use local variables in stored procedures?
本文介绍了如何在存储过程中使用局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我想从一个表中选择任何 id 并将它的值作为外键插入另一个表中,那么我将如何通过存储过程来做到这一点?
if I want to select any id from a table and want to insert it's value in another table as foreign key then how i will do it through stored procedure?
推荐答案
我将如何处理此问题的示例.
An example of how I would approach this.
DECLARE @MyID INT;
SET @MyID = 0;
SELECT @MyID = [TableID]
FROM [MyTable]
WHERE [TableID] = 99;
IF @MyID > 0
BEGIN
INSERT INTO [MySecondTable]
VALUES (@MyID, othervalues);
END
这篇关于如何在存储过程中使用局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文