Jump to content

Helpppp Teradata experts unnara?


ranku_mogudu

Recommended Posts

I need a solution to find all positions of a substring in a string that has  multiple occurrences.

 

ed., their is a soc sec  no  xxx-xx-xxxx lo '-' is in position 4 and 7. I want to get a query that determines both the positions.

Link to comment
Share on other sites

19 minutes ago, ranku_mogudu said:

I need a solution to find all positions of a substring in a string that has  multiple occurrences.

 

ed., their is a soc sec  no  xxx-xx-xxxx lo '-' is in position 4 and 7. I want to get a query that determines both the positions.

bro try this its complicated for you i guess but its microsoft sql (google lo dorikindi) hope it helps

 

declare @name nvarchar(max)
set @name ='ali reza dar yek shabe barani ba yek  dokhtare khoshkel be disco raft va ali baraye 1 saat anja bud va sepas... ali...'

Declare @a table (pos int)
Declare @pos int
Declare @oldpos int
Select @oldpos=0
select @pos=patindex('%ali%',@name) 
while @pos > 0 and @oldpos<>@pos
 begin
   insert into @a Values (@pos)
   Select @oldpos=@pos
   select @pos=patindex('%ali%',Substring(@name,@pos + 1,len(@name))) + @pos
end

Select * from @a

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...