Hi,
I have a table field with var char data type having values like TVM/345/2000,TVM/01/00,TSR/42/01 etc.I want to extract the sub string from first location to the second '/' location as TVM/345/.
Is there any built in function to solve is?

Thanks

Re: Extracting a substring from varchar field 80 80

SYNTAX

select substring(COLNAME, 1, CHARINDEX('/',COLNAME, CHARINDEX('/',COLNAME)+1)) FROM TABLENAME

EXAMPLE

select substring('TVM/345/2000,TVM/01/00,TSR/42/01', 1,CHARINDEX('/','TVM/345/2000,TVM/01/00,TSR/42/01',CHARINDEX('/','TVM/345/2000,TVM/01/00,TSR/42/01')+1))
Re: Extracting a substring from varchar field 80 80

Thank You Very much..
There is one more thing I want to do.
Can I update the fields like TVM/01/00 as TVM/01/2000?

Re: Extracting a substring from varchar field 80 80

before running this query keep backup of that column. or do it in dummy database

update tablename set colname=replace(colname,'TVM/01/00','TVM/01/2000')
Re: Extracting a substring from varchar field 80 80

It is not like that.The field is a dynamic field..I got the solution..Thanks for your support...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.