SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace command
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sonia_newbie
Starting Member

India
17 Posts

Posted - 03/10/2013 :  01:32:24  Show Profile  Reply with Quote
I have a sequence :

PH01000000G0240 P.he_genemodel_v1.0 CDS 120721 121773 . - . ID=PH01000000G0240.CDS;Parent=PH01000000G0240
PH01000001G0190 P.he_genemodel_v1.0 mRA 136867 137309 . - . ID=PH01000001G0190.mRNA;Parent=PH01000001G0190
.............................................
PH01278028G0010 P.he_genemodel_v1.0 CDS 27 501.. . - . ID=PH01278028G0010;Description="oereed"
PH01278104G0010 P.he_genemodel_v1.0 CDS 34 171 . - . ID=PH01278104G0010.CDS;Parent=PH01278104G0010


I want to replace PH0100000 by string but only in the first tab like
PH01000000 to string0
PH01000001 to string1
....
PH01278104 to string278104
PH01278028 to string278028


I want it to look like
string0G0240 P.he_genemodel_v1.0 CDS 120721 121773 . - . ID=PH01000000G0240.CDS;Parent=PH01000000G0240
string1G0190 P.he_genemodel_v1.0 mRA 136867 137309 . - . ID=PH01000001G0190.mRNA;Parent=PH01000001G0190
.............................................

string278028G0010 P.he_genemodel_v1.0 CDS 27 501.. . - . ID=PH01278028G0010;Description="oereed"
string278104G0010 P.he_genemodel_v1.0 CDS 34 171 . - . ID=PH01278104G0010.CDS;Parent=PH01278104G0010


I used sed command but It replaced every occurence oF PH01000000 to string0, I only want replacement only in first tab.

Also my command repalced PH01000000 to string00000 but i want PH01000000 to string0 remove the extra digits.

Is this possible?


Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/10/2013 :  04:08:13  Show Profile  Reply with Quote
Is the above content of a single column or are they under multiple columns?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sonia_newbie
Starting Member

India
17 Posts

Posted - 03/10/2013 :  10:11:09  Show Profile  Reply with Quote
These data are seperated by a tab!!
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 03/10/2013 :  11:37:56  Show Profile  Reply with Quote
STUFF(YourColumnName,1,CHARINDEX(CHAR(9),YourColumnName),'')
Go to Top of Page

sonia_newbie
Starting Member

India
17 Posts

Posted - 03/10/2013 :  12:58:47  Show Profile  Reply with Quote
Will this coommand replace my entries by string?
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 03/10/2013 :  13:10:48  Show Profile  Reply with Quote
Ah.. what I posted will remove the part before the first tab.

When you want to replace, what is the rule that you want to use? It seems like you want to have a fixed length to the number that is appended? For example PH01278104 --> string278104. Why is the 01 omitted? Is it because you want to keep only six digits, or is it something else?
Go to Top of Page

sonia_newbie
Starting Member

India
17 Posts

Posted - 03/10/2013 :  14:56:23  Show Profile  Reply with Quote
I want to replace PH0100000 by string but only in the first tab like
PH01000000 to string0
PH01000001 to string1
....
PH01278104 to string278104
PH01278028 to string278028

"stringvalue" is the format i need.
so i have to remove the PH01 from all entries but if used replace PH01 for all entries
PH01000000 beocmes string00000 instead of string0.
I hope i am not confusing.

Thanks
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 03/12/2013 :  06:13:07  Show Profile  Reply with Quote

DECLARE @tab TABLE( col VARCHAR(30))
insert into @tab
SELECT 'PH01000000G0240' UNION ALL -- String0G0240
SELECT 'PH01000001G0190' UNION ALL -- String1G0190
SELECT 'PH01278104G0010' UNION ALL String278104G0010
SELECT 'PH01278028G0210' --String278028G0210

SELECT 'String' +CAST(CAST(SUBSTRING(col, 5, 6) AS INT) AS VARCHAR(10))+ RIGHT(col, 5) FROM @tab

--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000