问题描述
我遇到一个问题....我编写了如下程序,需要在插入语句中调用它...
创建过程P_NextSequenceNo
AS
设置NOCOUNT ON
宣告@iReturn int
开始交易
SELECT @iReturn =来自dbo.EMPSEQUENCE
的序列UPDATE dbo.EMPSEQUENCE SET Sequence =(Sequence + 1)
提交交易
SELECT @iReturn
返回@iReturn
然后,我必须在插入语句下面的SeqNoKey列中调用该函数.
插入EmpSequence(发票编号,列1,列2,列3)
选择``SeqNoKey'',b.value3,0,a.value1,c.value4
来自表1 a,
在a.value1 = b.value3上加入table3 b
并在c.value4 = a.value1
am having one issue.... i write a procedure like below, and need to call it in insert statement...
CREATE PROCEDURE P_NextSequenceNo
AS
SET NOCOUNT ON
DECLARE @iReturn int
BEGIN TRANSACTION
SELECT @iReturn = Sequence FROM dbo.EMPSEQUENCE
UPDATE dbo.EMPSEQUENCE SET Sequence = ( Sequence + 1 )
COMMIT TRANSACTION
SELECT @iReturn
RETURN @iReturn
And after that i have to call that function into below Insert Statement in place of SeqNoKey column.
Insert Into EmpSequence (InvoiceNo, column1, column2, column3)
select ''SeqNoKey '', b.value3, 0, a.value1, c.value4
from table1 a,
join table3 b on a.value1=b.value3
and join table2 c on c.value4 = a.value1
推荐答案
public void InsertRecord(int StudentId, string StudentName)
{
//Sql Connection Object
SqlConnection conn = new SqlConnection("your connection string");
//Sql Command Object
SqlCommand command = new SqlCommand("InsertSpName", conn);
command.CommandType = CommandType.StoredProcedure;
//now execute the stored procedure
command.ExecuteNonQuery();
}
请记住,这只是一个想法,您将如何做事情.不要在此代码中指出问题:)
Remember this is just an idea how you would do things. Don''t pin point the problems in THIS code :)
这篇关于在插入语句中使用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!