Solved

Split URL for a SELECT statement

Posted on 2013-10-29
3
372 Views
Last Modified: 2013-10-29
Hi guys,

I've upgraded the articles section on my site from ASP classic to C#, and I'm having trouble isolating a string on the URL to select the page number. At present, my site URL would look like this:

Sitename/ArticleName/1

This would give me page 1. If I change the URL to:

Sitename/ArticleName/2

I want to be able to view the second page - can anyone show me how to isolate the number after the split and then declare it as a variable in order to use it in my select statement?

Any help much appreciated, as ever.
0
Comment
Question by:RossLiversidge
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39608816
declare @test varchar(50)
set @test = 'Sitename/ArticleName/20'

select substring(
                          @test,
                                    len(@test) - charindex('/', reverse(@test)) + 2,
                                    charindex('/', reverse(@test)))
0
 

Author Comment

by:RossLiversidge
ID: 39608836
I should have mentioned that I'm using Razor Syntax, is it possible to translate the above accordingly?
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39608844
Just pass in the entire url.  The query will take find the number after the /
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question