Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am having one issue.... i write a procedure like below, and need to call it in insert statement...

SQL
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.

SQL
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
Posted
Updated 2-May-12 0:23am
v3
Comments
Reiss 2-May-12 7:07am    
You appear to be affectively spoofing a primary key - any reason why a standard PK won't solve your issue?

1 solution

SQL
DECLARE @iReturn INTEGER

SET @iReturn=EXEC(P_NextSequenceNo)


Insert Into EmpSequence (InvoiceNo, column1, column2, column3)
select @iReturn , 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
 
Share this answer
 
Comments
karthika -chennai 2-May-12 7:25am    
hello friend:

it shows the following error

Incorrect syntax near the keyword 'EXEC'.
karthika -chennai 2-May-12 7:41am    
more over for all records it shows the same sequence number,,...
i need the continuous generation number for each record.....
bbirajdar 2-May-12 7:50am    
If you want to performs calculations on row by row basis , you will need to user CURSOR in sql.

http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/
karthika -chennai 3-May-12 2:27am    
thank you friend

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900