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 |
|
bhanu_9
Starting Member
1 Post |
Posted - 2005-09-01 : 00:56:07
|
| Hi All , I would like to create a procedure which will take an array as an argument and the array should be first split and then it should be stored in the temp table so that when i use a select statement the data should be displayed asTEST+REST-WEST *HIGH etcthe procedure should be like this X(Array as argument) this array will have pattern matching characters like +,- etc so the array will be "TEST+WEST-REST*HIGH" etc this array has to be split stored in the table and then when the select statement is issued should print TEST+REST-WEST *HIGH Please provide me with the code I have written the following code can any one tell me what has to be done so that i get the desired output drop procedure Split_String_Pattern -- drops the procedure /* Creating the procedure which will take a string as an argument and that string is going to be split when ever we encounter a specific pattern. The pattern symbols could be */+- */Create procedure Split_String_Pattern ( @Array varchar(2000)) ASset nocount on SET TEXTSIZE 0 -- Create variables for the character string and for the current position in the string. DECLARE @position int, @string VARCHAR(2000),@SSUBSTR VARCHAR(2000),@nASSCIIVAL INT,@SSTR VARCHAR(2000) SET @SSTR='' -- Initialize the current position and the string variables. SET @position = 1 --Initialization of the current position variable SET @string = @Array -- Initialization of the string variable WHILE @position <= DATALENGTH(@string) BEGIN SET @SSUBSTR=SUBSTRING(@string, @position, 1) SET @nASSCIIVAL=ASCII(@SSUBSTR) IF (@nASSCIIVAL >=65 AND @nASSCIIVAL < 91) OR (@nASSCIIVAL >= 97 AND @nASSCIIVAL < 123) OR (@nASSCIIVAL >=48 AND @nASSCIIVAL<=57) BEGIN SET @SSTR=@SSTR+@SSUBSTR END ELSE BEGIN PRINT @SSTR PRINT @SSUBSTR select @SSTR select @SSUBSTR SET @SSTR='' END SET @position = @position + 1 ENDbegin transaction insert into bhanu (out_value) values (@SSTR);commit transaction GOselect * from bhanu/* Execution of the procedure is done as follows */Declare @ArrayString varchar(4000)set @ArrayString ='TEST+WEST-REST*HIGH 'exec Split_String_Pattern @ArrayStringassis me fast please |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|