?
Solved

Split URL for a SELECT statement

Posted on 2013-10-29
3
Medium Priority
?
389 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 40

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 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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 ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

801 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