Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

String Operation in Stored Procedure Expand / Collapse
Author
Message
Posted Friday, May 22, 2009 12:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, May 22, 2009 12:53 AM
Points: 1, Visits: 0
I am Passing a String in a Stored Procedure for example
'1,2,3,4,5'
and inside the stored procedure i need to remove the single quotes on the both sides of the string and to store the rest string to a variable inside the Stored Procedure
Can i apply some operation to the string
Post #721857
Posted Friday, May 22, 2009 2:47 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, October 17, 2012 10:33 AM
Points: 390, Visits: 405
Hi there,

you can use replace function which has following syntax
-: replace(@stringvar,charactertoreplace,newcharacter)

for e.g.

DECLARE @HashText nvarchar(10)
set @HashText= '''1,2,3,4'''
declare @grate nvarchar(10)
set @grate=replace(@HashText,'''','')
select @grate
Post #721894
Posted Friday, May 22, 2009 12:43 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:31 PM
Points: 11,265, Visits: 13,027
What are you doing with the string inside the stored procedure? You probably should look into a Split Function that puts the values into a table. Check out this article for that.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #722324
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse