Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove string before or after a specified character

Status
Not open for further replies.

katehol

Technical User
May 2, 2007
57
GB
I need to split up some web addresses that are being stored in my database. I currently have strings in the format of

{name}/web/guest/home

I want to be able to split this into 2 columns - one for the name and one for the remainder of the web page, so that I can count individual users and individual page hits. So I would end up with one new column called 'name' (with all of the names in brackets{}) and one new column called page (with just the trailing web page address).

Am totally stuck on this, so any help would be appreciated.

Thanks

 
Hi,

How about something like:
Code:
SELECT
Left(YourWebAddress, InStr(1, YourWebAddress, "/") - 1) as WebName,
Right(YourWebAddress, Len(YourWebAddress) - (InStr(1, YourWebAddress, "/") - 1)) as WebPage
FROM YourTable...
It's not the most elegant though [wink]

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks for that - unfortunately, InStr is not recognised in SQL Server. :(
 
Sorry, my mistake I forgot which forum I was in there [banghead]

You can use CHARINDEX() to find the position of the / in the column rather than INSTR()

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks Harley - worked a treat

Used this in the end

SELECT
Left(YourWebAddress, CHARINDEX('/',YourWebAddress) - 1) as WebName,
Right(YourWebAddress, Len(YourWebAddress) - (CHARINDEX('/',YourWebAddress) - 1)) as WebPage
FROM YourTable
 
Glad I could help [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top