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 2000 Forums
 SQL Server Development (2000)
 inserting a letter every x places

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-11-27 : 03:10:29
i make a query and i want on a certain col say called col1
to insert every x letter my own string for example :
col1
--------
dog
cat

afeter inset :
dAAAog
cAAAat
how can i do this?
thnaks in advance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-27 : 03:16:10
Use STUFF function

SELECT STUFF('dog', 2, 0, 'AAA'), STUFF('cat', 2, 0, 'AAA')


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-11-27 : 03:22:42
thnaks alot
is there a way making it happen more thne once on a string likeL:
abracadabra ===>> abAAraAAcaAAdaAAbrAAa


Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-27 : 03:37:32
[code]declare @s varchar(1000), @r varchar(1000)

select @s = 'abracadabra',
@r = ''

select @r = @r + q.g
from (
select substring(@s, 1 + 2 * number, 2) + CASE WHEN number < len(@s) / 2 THEN 'AA' ELSE '' END g
from master..spt_values
where name is null
and number between 0 and len(@s) / 2
) q

select @r[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-11-27 : 03:39:25
ok thnaks laot

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-27 : 07:46:02
quote:
Originally posted by pelegk2

thnaks alot
is there a way making it happen more thne once on a string likeL:
abracadabra ===>> abAAraAAcaAAdaAAbrAAa


Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

Why do you need this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -