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
 SQL Server Development (2000)
 SQL right parse statement

Author  Topic 

bntringa
Starting Member

5 Posts

Posted - 2006-05-17 : 13:26:51
Hey all,

I have the following statement that I have utilized successfully in Access to basically parse out all data to the right of a specified character, but this does not translate directly to SQL:

StreetName: Right$([ADDRESS],(Len([ADDRESS])-(InStr(1,[ADDRESS]," "))))

In this case, it parses out a street name from the ADDRESS field where the data would be something like (100 Main Street) and returns simply (Main Street).

I know that InStr is not recognized by SQL. Does anyone have an alternative means for this?

thanks!

- Brian

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-05-17 : 13:37:52
You can use the CHARINDEX and SUBSTRING functions to do this.

You can read about both functions in SQL Server Books Online.

CODO ERGO SUM
Go to Top of Page

bntringa
Starting Member

5 Posts

Posted - 2006-05-17 : 14:13:23
Thanks for the tip!

Here's what I've come up with:

SUBSTRING(NAME, CHARINDEX('-', NAME) + 2, LEN(NAME)) AS Test

This takes everything that is two characters to the right of '-'. This seems to work just fine.

thanks!

- Brian
Go to Top of Page
   

- Advertisement -