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
 Transact-SQL (2000)
 Splitting out first few portions of a string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-31 : 09:01:13
Rajaraman S writes "Hi,

I have a field in a table which contains strings in the form of AAQG.DE,AAQG.MU/AAQG.RE, DYKG_p.DE..like this. I want to extract the portion of the string upto dot. The length of the string upto the dot may vary, it is not fixed. The length after the dot also vary. So can I extract the portion of the string using an SQL query? If so, how? Any kind of help is great. Thanks in advance.


Regards
Rajaram"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-31 : 09:10:07
declare @str varchar(100)
set @str='AAQG.DE,AAQG.MU/AAQG.RE, DYKG_p.D'
select substring(@str,1,charindex('.',@str,1)-1)
set @str='AAQGDE,AAQG.MU/AAQG.RE, DYKG_p.D'
select substring(@str,1,charindex('.',@str,1)-1)


Madhivanan

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

Norwich
Posting Yak Master

158 Posts

Posted - 2006-01-31 : 09:12:10
[code]Declare @var varchar(50),
@pos int,
@newVar varchar(50)

Set @var = 'AAQG.DE'

Select @pos = charindex('.',@var)

Select @newvar = left(@var,@pos - 1)

Print @newVar[/code]

Regards
N

The revolution won't be televised!
Go to Top of Page

Norwich
Posting Yak Master

158 Posts

Posted - 2006-01-31 : 09:14:04
I guess Madhivanan beat me to it!

N

The revolution won't be televised!
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-01-31 : 10:34:52
Do you want to extract the other parts of the string too?

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-01 : 09:36:57
But we rarely get response from Temporary members

Madhivanan

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

- Advertisement -