Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends ,
I have a store procedure in my DB that create a unique code for me.It was working fine from last 1 year , but from last 2 week , showing unusual error after each 2 or 3 days .Strange thing is that it again start working fine after dropping and recreating procedure with same code (Error:-Failed to convert string to int).Please help me solve it .Procedure is given below

SQL
CREATE procedure [dbo].[select_purdrscode]
(@branchid int) as begin
SET NOCOUNT ON
if exists(select 1  from purdrs where branchid=@branchid)
begin
select top 1
b.branchcode +replace(CONVERT(VARCHAR(30),dateadd (minute, 330,getutcdate()),105),'-','')
+ cast((cast((REPLACE( d.drscode, left(d.drscode,11), '' ))as int)+1)as varchar(200))
 as drscode
 from PURdrs d inner join branch b
on b.branchid=d.branchid where d.branchid=@branchid
order by d.drsid desc
end
else
begin
select top 1
branchcode+replace(CONVERT(VARCHAR(30),dateadd (minute, 330,getutcdate()),105),'-','')
+'1' as drscode
 from branch   where branchid=@branchid
end
end




Thank You
Posted
Updated 16-Mar-15 22:05pm
v2

1 solution

It means you have some data that is breaking the sql. You'll need to debug it since we do not have access to your database.
 
Share this answer
 

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