Solved

Split URL for a SELECT statement

Posted on 2013-10-29
3
361 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query Missing Money orders... 6 73
ConsoleSql 1 22
cs.Designer Issue(2) 2 23
Calling stored proc in EDMX 11 19
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now