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
 General SQL Server Forums
 New to SQL Server Programming
 Substring and Replace

Author  Topic 

shemayb
Posting Yak Master

159 Posts

Posted - 2009-01-05 : 07:11:11
Hi.

I really needed your help. Please give me ideas on my scenario..
Thank you.

My scenario is this.

I have a description which has a prefix A or B. For example AFT and BFT.

i wanted to get the first letter of my description like in the example i want to get the A and the B.

I tried using substring. And luckily i got the first letter.
but i do not know what will i do with the next step.

The next step is if the first letter of the description that i inserted is A, i will create another one with the same description but replace A with B.

For example if i inserted AFT, i will replace it with BFT and insert it again. It's like i'm inserting two descriptions.

I know my scenario is confusing, but i will try to explain well if you have any questions.

Thank you so much!

Funnyfrog

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-01-05 : 07:18:52
Insert another row you mean ?
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-05 : 07:19:20
create proc usp_sampleproc
(
@str varchar(12)
)
as
set nocount on
begin
insert into urtable select @str
insert into urtable select replace(@str,substring(@str,1,1),'b')

end
set nocount off
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-05 : 07:22:55
or use left also inplace of substring

insert into tt3 select replace(@str,left(@str,1),'b')
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-05 : 07:23:09
insert into urtable select column_name
insert into urtable select replace(column_name,left(column_name,1),'b')


Jai Krishna
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2009-01-05 : 07:43:15
Thank you so much..

I will try that.



Funnyfrog
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2009-01-05 : 07:43:51
yes, insert another row

Funnyfrog
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-05 : 07:44:31
ur welcome
Go to Top of Page

shemayb
Posting Yak Master

159 Posts

Posted - 2009-01-05 : 07:52:09
That was really a great help for me:)

Funnyfrog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-05 : 08:36:06
isnt this enough?

INSERT INTO Table
SELECT 'B'+SUBSTRING(Col,2,LEN(Col))
FROM Table
WHERE LEFT(Col,1)='A'
Go to Top of Page
   

- Advertisement -