tsql - Strip off any characters from a string in SQL Server -
tsql - Strip off any characters from a string in SQL Server -
i'm trying write stored procedures give next value on row.
in case, i'm sending reference number , stored procedure returns next ref number using min
, >
. ref number in table includes characters 123gf, 256er, 25gd gives me error when converting varchar
int
.
how strip off non-numerical number before comparing value passing value?
this current procedure code:
create procedure [dbo].nextprevious @refid integer, @next bit begin set nocount on; declare @lreturn integer if(@next = 1) select ref table ref =( select min(ref) table ref > @refid) else select ref table ref =( select max(ref) [ref ref < @refid) select @lreturn = @@rowcount homecoming @lreturn end go
if using sqlserver, below
other solution using replace function:
select replace(ref,'a','') table --to cutting off 1 char select replace(replace(ref,'a',''),'b','') table --to cutting off , b char
likewise chars
sql-server tsql stored-procedures
Comments
Post a Comment