Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
my query is
SQL
 @name_of_inst varchar(150),
 @signatory_mous varchar(150),
 @draft_mous varbinary(MAX),
 @reg_no char(12) 
AS

DECLARE @inserr1 as int
declare @count as int
set @count = 1
begin transaction OT 

if exists(select srno from mous_info where reg_no = @reg_no)
set @count =(select srno from mous_info where reg_no = @reg_no)+1
	insert into mous_info(reg_no,name_of_inst,signatory_mous,is_mous_ready,srno,draft_mous) 
	values(@reg_no,@name_of_inst,@signatory_mous,'True',@count,@draft_mous)
	select @inserr1=@@ERROR 

	if @inserr1=0
	   begin
		  commit transaction OT
		  return 0
	   end
	   else
	   begin          
		 rollback transaction OT          
		 return 1
	 end
Posted
Updated 30-Apr-14 22:25pm
v2
Comments
phil.o 1-May-14 4:27am    
On which line? Remember a title is not meant to hold a question or an entire error message; it has to summarize briefly the issue.<br><br>
In your post, you should show the entire error message, line number should be indicated. And I guess the first line of your stored procedure is missing.
You seem to have more than one record with the same reg_no in your table.

set @count =(select srno from mous_info where reg_no = @reg_no)+1
This query is returning more than one value.

Use top to restrict to the first value e.g.
set @count =(select top srno from mous_info where reg_no = @reg_no)+1
 
Share this answer
 
Comments
sanjaysgh 1-May-14 4:40am    
sir its working but number is not incresing like 1,2,3 still getting srno like 1,2,2,2,...

plz help
from ur code
SQL
set @count =(select srno from mous_info where reg_no = @reg_no)+1

make sure 'select srno from mous_info where reg_no = @reg_no' returns single value
if the query returns more than one rows ,u need to correct it.
good luck ;-)

this code may work try
SQL
set @count =(select MAX(srno) from mous_info where reg_no = @reg_no)+1
 
Share this answer
 
v2
Comments
sanjaysgh 1-May-14 4:57am    
tnak u sir its working fine thanks a lot

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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