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.
Author |
Topic |
sarfrazabdu
Starting Member
5 Posts |
Posted - 2014-01-21 : 16:10:36
|
Hi All,I have a doubt ..I have a string which is passed as parameter in a stored procedure.... the string is like this "sar[abc]zas"i wanted to get all combination of this(with the letters inside the brackets]. there can be more tahn one brackets also insode a string amking the number of combination strings more..like sarazassarbzassarczasCould you lease help me .. it is very important for me..sarfraz |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2014-01-21 : 19:13:42
|
Your approach seems right but without seeing how you are using the parameter, it is difficult impossible to know where you are going wrong. (I am assumng that something went wrong)=================================================A man is not old until regrets take the place of dreams. - John Barrymore |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-22 : 07:31:28
|
quote: Originally posted by sarfrazabdu Hi All,I have a doubt ..I have a string which is passed as parameter in a stored procedure.... the string is like this "sar[abc]zas"i wanted to get all combination of this(with the letters inside the brackets]. there can be more tahn one brackets also insode a string amking the number of combination strings more..like sarazassarbzassarczasCould you lease help me .. it is very important for me..sarfraz
so far as you use parameter with like operator it should work fine------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
sarfrazabdu
Starting Member
5 Posts |
Posted - 2014-01-22 : 11:38:28
|
It seems, i didot ake my question very clear. Hope this would make it more clearer.I have a stored procedure (This SP is used to replace a n existing content with a new conetnt by searching for that content in a big text document ). The new conetnt and existing conetnt will be sent as parameters to the SP.Consider the paramaters as @oldContent varchar(100),@newContent varchar(100),@WholeContent varchar(500),Inside the stored procedure , we have a replace function , which would be called set @ WholeContent = REPLACE(@WholeContent, @oldContent, @newContent)and it was working fine ,Now there is a change in the business , the trick is that we are going to have multiple old values ( which will be sent as a single parameter)The values that will be sent will be like belowFor example ,oldContent = ‘sa[abc]f[wes]’newContent =’sam’The new content will have only 1 value say ‘sam’, but the old content can have different values , the old value sent in this example is sa[abc]f[wes]Now we should be decompose the old content to saafw, sabfw,………..sacfs….(total 9)Then we call the function replacefunction which replaces the oldconetnt( text created by all combination) with the new one.…. So, set @ WholeContent = REPLACE(@WholeContent, @oldContent, @newContent)this should be called multiple times.Just was looking how to implement this decomposition of the old values to different values and calling the replace function in a very efficient way .Is there any build in function which can decompose the same and give different combination?sarfraz |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-01-22 : 12:51:10
|
As far as I know you'd have to make your own custom function to do that sort of replace. It may (or may not) be easier to do with a CLR function. But, I don't know of a built in SQL function that will do that.However, to help clarify, could you post some actual data and the expected results to help illustrate how the replace would work? |
|
|
Kristen
Test
22859 Posts |
Posted - 2014-01-25 : 14:43:32
|
I have used RegEx on the SQL box to do this type of thing before, but hooking SQL up to external components like that leads to instability in my view, so I have only ever done it for a one-off task. Can't event remember how I did it now - OLE probably! |
|
|
|
|
|
|
|