Over the next few days we are going to start the migration to a new forum application. I'm going to start with high post count and active users. You may receive an invitation to the new forums. It's not spam. It's just me trying to seed the user base. My goal is to open it up over the weekend.

Once we open the site we'll block registrations here. We should be open shortly on the new site.

SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Any simple way to get querystring value from a url
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 02/20/2013 :  06:21:21  Show Profile  Reply with Quote
Any simple way to get querystring value from a url without charindex and substring
I wanted to get the querystring value of entryid

http://www.mysite.com/Default.aspx?TabId=330&EntryId=1



Kamran Shahid
Principle Engineer Development
(MCSD.Net,MCPD.net)

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/20/2013 :  07:48:29  Show Profile  Reply with Quote
Are you running into any issues when using charindex and substring? In any case, the following does not use either of those functions:
DECLARE @x VARCHAR(256) = 'http://www.mysite.com/Default.aspx?TabId=330&EntryId=1';
SELECT STUFF(@x,1,PATINDEX('%&EntryId%',@x),'')
Go to Top of Page

donjosdon
Starting Member

India
1 Posts

Posted - 04/11/2014 :  06:22:06  Show Profile  Reply with Quote
I tried the below and it worked.

DECLARE @x VARCHAR(256) = 'http://www.mysite.com/Default.aspx?EntryId = 1&a=1&TabId=330';

--another query string combination
/*DECLARE @x VARCHAR(256) = 'http://www.mysite.comDefault.aspx?TabId=330&EntryId = 1&a=1';*/

SELECT STUFF(@x,1,PATINDEX('%EntryId%',@x)-1,'')
select LTRIM(RTRIM(Replace(REPLACE(SUBSTRING(STUFF(@x,1,PATINDEX('%EntryId%',@x)-1,''),0,
(case when CHARINDEX('&',STUFF(@x,1,PATINDEX('%EntryId%',@x)-1,''),1)=0 then 100 else CHARINDEX('&',STUFF(@x,1,PATINDEX('%EntryId%',@x)-1,''),1) end)
),'EntryId',''),'=','')))

Thanks
Joseph Don
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000