Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
ALTER proc  [dbo].[pGetCode] --'InvestmentGroup', 'Code', 'I',5 
(

@TableName  varchar(20),

@ColumnName varchar(20)='',
@key varchar(10),
@TotalDigits int 
)
as
begin
create table #temp (incode varchar(20));
declare @incode varchar(20);
declare @a varchar(10)=null;
declare @length int = 1;
declare @string varchar(10) ='';
declare @startposition varchar(20);
declare  @query varchar(100);

set @startposition=Len(@key)+1;


select @query='insert into #temp select   SUBSTRING( max('+@ColumnName+') ,'+@startposition+','+@TotalDigits+') as  int  from  '+ @TableName +'  where '+@ColumnName+' like '''+ @key +'0%'''
exec (@query)
select @incode = incode from #temp;
select @incode
drop table #temp;
end
Posted
Updated 2-Jan-13 17:43pm
v2

1 solution

You're trying to use 'as int' to convert a string to an int and it's failing. In fact, all of this is ugly as hell. Try using CONVERT. Or better yet, select the values as a string and find out why your values don't convert to int. That is the issue, just like the error says
 
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