Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Clean parameter value from string value

Author  Topic 

Ciupaz
Posting Yak Master

232 Posts

Posted - 2014-05-05 : 04:36:49
Hello all,
I a stored procedure I have a parameter like:

@CAId varchar(20)

Before I use it in this procedure, I have to check if this
parameter value contains the string "new", followed by a number,
and then remove the "new" string.

So, if I receive:

@CAId = 'new365" -> @CAId = '365'

@CAId = '150' -> @CAId = '150'


How can I accomplish it?

Thanks a lot.


Luis

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-05-05 : 04:40:17
[code]
declare @CAID as varchar(50)

set @CAId = 'new365'
--set @CAid='150'
select @CAID, replace(@CAid,'new','') as Numb
[/code]


sabinWeb MCP
Go to Top of Page

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-05-05 : 05:01:33


DECLARE @CAID AS VARCHAR(50)
SET @CAId = 'new365'
--set @CAid='150'
SELECT SUBSTRING(@CAId,PATINDEX('%[0-9]%',@CAId),LEN(@CAId)) AS Number


---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page

Ciupaz
Posting Yak Master

232 Posts

Posted - 2014-05-05 : 05:29:48
Perfect, thank you all very much.

Luis
Go to Top of Page
   

- Advertisement -