Author |
Topic |
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2012-12-27 : 02:37:20
|
I have a content in which i have certain page name with ended with .aspxhref="http://www.mysite.com/MyPage.aspx"I wanted to list of all such distinct entries in all of my contenthow can i retrieve them.At the moment it simply selected all contentSELECT [MYContents] FROM [dbo].[MYTable] WHERE [MYContents] LIKE '%.aspx%' Kamran ShahidPrinciple Engineer Development(MCSD.Net,MCPD.net) |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-27 : 02:51:48
|
-- To avoid duplicate entries, use DISTINCT keywordSELECT DISTINCT [MYContents] FROM [dbo].[MYTable] WHERE [MYContents] LIKE '%.aspx%' --If u want to get only filename part from that ContentSELECT DISTINCT RIGHT([MYContents], CHARINDEX('/', REVERSE([MYContents]))-1 ) AS fileNamesFROM [dbo].[MYTable] WHERE [MYContents] LIKE '%.aspx%' --Chandu |
|
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2012-12-27 : 03:05:09
|
I need to get full href="http://www.mysite.com/MyPage.aspx" entries with in the content whcih also have other body element.I have minor help from [url]http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/c6da7ac1-d102-482f-a2d6-fcbb17c21f70[/url]Kamran ShahidPrinciple Engineer Development(MCSD.Net,MCPD.net) |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-27 : 05:23:42
|
Try this...SELECT DISTINCT link FROM [dbo].[MYTable]CROSS APPLY dbo.GetLinks([MYContents])--Chandu |
|
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2012-12-27 : 05:43:47
|
Thanks May be some problem in function or data as i am getting error Invalid length parameter passed to the SUBSTRING function.Remember i may have multiple hrefKamran ShahidPrinciple Engineer Development(MCSD.Net,MCPD.net) |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-27 : 06:24:12
|
Somewhere this value (@endpos - @strtpos) is getting negative..SO check condition for @endpos >= @strtpos--Chandu |
|
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2012-12-27 : 09:45:11
|
select z.* from (select 'href="MyFirstPAge.aspx"href="http://www.test.com/2009/05/aa-bb.html"href="MySecondPage.aspx"' as content) xcross apply dbo.GetLinks(x.content) zis the sample of error dataKamran ShahidPrinciple Engineer Development(MCSD.Net,MCPD.net) |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-28 : 00:54:28
|
Small modification ALTER function [dbo].[GetLinks] (@t nvarchar(max)) returns @Links table (link nvarchar(max))asbegin declare @strtpos int = PATINDEX('%href="http%.aspx"%', @t) declare @endpos int = 0 declare @lnk nvarchar(max) while @strtpos > 0 begin select @endpos = PATINDEX('%.aspx"%', @t)+ 5 IF @endpos >@strtpos BEGIN SELECT @lnk = substring(@t ,@strtpos, @endpos - @strtpos) ,@t= RIGHT (@t, len(@t) - @endpos) ,@strtpos = PATINDEX('%href="http%.aspx"%', @t) insert @Links values(@lnk ) END ELSE BREAK end return endGO--Test DECLARE @Tablevar TABLE(vars varchar(1000))INSERT INTO @Tablevar VALUES('scfbg vubvfswdhicosadsjiao"'),('href="http://www.mysite.com/MyPage.aspx"'),( 'http://www.mysite.com/MyPage.aspx'), ('I have a content in which i have certain page name with ended with .aspxhref="http://www.mysite.com/MyPage.aspx"I wanted to list of all such distinct entries in all of my contenthref="http://www2.mysite.com/My444Page.aspx" ') ,('href="MyFirstPAge.aspx"href="http://www.test.com/2009/05/aa-bb.html"href="MySecondPage.aspx"' ) --Chandu |
|
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2012-12-28 : 06:07:23
|
Nice check bandi but it didn't get the correct answerSample data is<a shape="rect" href="http://www.qwewqe.fda.gov/wqewqe/pdf8/wewe.pdf" target="_blank">System</a> rket. </p>been calling for <a shape="rect" href="http://www.sdfdsf.org/news/sdfsdf/sdfsdfsdf.html" target="_blank">rocess</a>,in 2010, <a shape="rect" href="http://www.gfhgfh.com/defective-medical-devices/fghfgh-takes-aim-at-501k-fgh-device-approvals" target="_blank"> changes. </p><p style="text-align: justify">The <a shape="rect" href="fghfghfgh.aspx" target="_blank"> substantially equivalent.</a> </p><p style="text-align: justify">Per th </p><p style="text-align: justify">market. </p> <p style="text-align: justify">The <a shape="rect" href="asdd.aspx" target="_blank">sub.</a> </p><p style="text-align: justify"> Perhaps</p><p style="text-align: justify">t of a <a shape="rect" href="http://www.asdasdasd.com/view.aspx?rid=67920" target="_blank">one-in-eight</a> revision </p><p style="text-align: justify">Critics de <a shape="rect" href="http://www.sdfsdf.com/2009/05/fda-sdfsdf-devices-without-scrutiny-putting-dsf-at-risk.html" target="_blank">5 </p><p style="text-align: justify">We </p><p style="text-align: justify">If </p><p style="text-align: justify"> <a shape="rect" href="SDFSDFSDF.aspx">sdfsdf</a> </p><p style="text-align: justify"><a shape="rect" href="asd324234dsdasd.aspx">asd</a> </p><p style="text-align: justify"> <a shape="rect" href="sadsad.aspx">sasdasdasd</a> Kamran ShahidPrinciple Engineer Development(MCSD.Net,MCPD.net) |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-28 : 07:01:49
|
quote: Originally posted by kamii47 Nice check bandi but it didn't get the correct answerKamran ShahidPrinciple Engineer Development(MCSD.Net,MCPD.net)
what is the problem now?In your sample data ('href="MyFirstPAge.aspx" href="http://www.test.com/2009/05/aa-bb.html"href="MySecondPage.aspx"'), there is no URL which is in the form of '%href="http%.aspx"%'href="MyFirstPAge.aspx" --> Missing httphref="http://www.test.com/2009/05/aa-bb.html" --> Missing .aspxhref="MySecondPage.aspx" --> Missing http--Chandu |
|
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2012-12-28 : 07:08:31
|
Please check with the sample data. [may be we have posted almost same time]Kamran ShahidPrinciple Engineer Development(MCSD.Net,MCPD.net) |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-28 : 08:18:51
|
yes there is a loop hole in that function..we are checking for this pattern '%href="http%.aspx'.. right? Thats why it is taking starting from href="http and ending at .aspxhref="http://www.qwewqe.fda.gov/wqewqe/pdf8/wewe.pdf" target="_blank">System</a> rket. </p>been calling for <a shape="rect" href="http://www.sdfdsf.org/news/sdfsdf/sdfsdfsdf.html" target="_blank">rocess</a>,in 2010, <a shape="rect" href="http://www.gfhgfh.com/defective-medical-devices/fghfgh-takes-aim-at-501k-fgh-device-approvals" target="_blank"> changes. </p><p style="text-align: justify">The <a shape="rect" href="fghfghfgh.aspx"am trying to solve this.......--Chandu |
|
|
|