Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
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 2-Jan-13 18:26pm
Edited 2-Jan-13 18:43pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,740
1 DamithSL 5,769
2 Sergey Alexandrovich Kryukov 5,424
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100