Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Split URL for a SELECT statement

Posted on 2013-10-29
3
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 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 41

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

610 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