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
 Extracting a string

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2011-04-20 : 10:42:04
Dear All,

I need to make join using 'cstid'.But in one table this cstid is combined with string

ie.
cstid(cst table)
FI123546_issued
FI123555_issued
FI110001_issued

I want to extract the first part ie (FI123546) from FI123546_issued and then i need to make a join with temp table ie.(cst.cstid = temp.cstid)

in temp table cstid is like 'FI123546'

How to do this.Any help would be highly appreciated.

Regards,
SG

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-20 : 10:46:36
left(cstid,8) would be too easy, so...
substring(cstid,1,charindex('_',cstid)-1)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-20 : 10:47:05
SELECT * FROM cst c
INNER JOIN temp t ON LEFT(c.cstid, CHARINDEX('_', c.cstid)-1)=t.cstid

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-20 : 10:47:06
left(cstid,8)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-20 : 10:47:57
OMG! I am too slow.



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -