Split URL for a SELECT statement

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.
RossLiversidgeAsked:
Who is Participating?
 
Kyle AbrahamsSenior .Net DeveloperCommented:
declare @test varchar(50)
set @test = 'Sitename/ArticleName/20'

select substring(
                          @test,
                                    len(@test) - charindex('/', reverse(@test)) + 2,
                                    charindex('/', reverse(@test)))
0
 
RossLiversidgeAuthor Commented:
I should have mentioned that I'm using Razor Syntax, is it possible to translate the above accordingly?
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Just pass in the entire url.  The query will take find the number after the /
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.