<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-29286778.post6324807287672434139..comments</id><updated>2008-07-29T14:01:13.445-04:00</updated><category term='Feature Creeper'/><category term='FAQs and not so FAQs'/><category term='SQL Puzzles'/><category term='Pass time with SQL'/><title type='text'>Comments on SQL Garbage Collector: A Scenario to Ponder #11</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.sqlpointers.com/feeds/6324807287672434139/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29286778/6324807287672434139/comments/default'/><link rel='alternate' type='text/html' href='http://www.sqlpointers.com/2006/11/scenario-to-ponder-11.html'/><author><name>Omnibuzz</name><uri>http://www.blogger.com/profile/04342835880399785393</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-29286778.post-6204125679916479589</id><published>2006-12-21T01:33:00.000-05:00</published><updated>2006-12-21T01:33:00.000-05:00</updated><title type='text'>Here is an implementation that will work in SQL Se...</title><content type='html'>Here is an implementation that will work in SQL Server 2005. If you can think of a solution in SQL Server 2000 or a better solution do let me know.&lt;br /&gt;&lt;br /&gt;declare @start char,@end char&lt;br /&gt;set @start = 'c'&lt;br /&gt;set @end = 'd';&lt;br /&gt;with cte as&lt;br /&gt;(&lt;br /&gt;SELECT city1,city2,distance FROM #DISTANCE_TBL&lt;br /&gt;union all&lt;br /&gt;SELECT city2,city1,distance FROM #DISTANCE_TBL&lt;br /&gt;), &lt;br /&gt;cte1 as&lt;br /&gt;(select city1 as start,city2 as dest, cast(city1 + '-&gt;' + city2 as varchar(100)) as pth,&lt;br /&gt;distance&lt;br /&gt;from cte where city1 = @start&lt;br /&gt;union all&lt;br /&gt;select a.start,b.city2,cast(pth  + '-&gt;' + city2 as varchar(100)), a.distance + b.distance from cte1 as a, cte as b&lt;br /&gt;where a.dest = b.city1 and charindex(b.city2 + '-&gt;', a.pth) = 0&lt;br /&gt;)&lt;br /&gt;select top 1 * from cte1&lt;br /&gt;where dest = @end&lt;br /&gt;order by distance, len(pth)&lt;br /&gt;&lt;br /&gt;This solution is based on pattern matching in a string. I somehow don't like this solution as there are a few situations , though far-fetched, where it might fail. &lt;br /&gt;&lt;br /&gt;And, for those who are following these puzzles, please do excuse me for being inactive for the past few days. My job is demanding my blogging time. And the situation is going to continue for a few more days :( &lt;br /&gt;&lt;br /&gt;Wish me luck....</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/29286778/6324807287672434139/comments/default/6204125679916479589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/29286778/6324807287672434139/comments/default/6204125679916479589'/><link rel='alternate' type='text/html' href='http://www.sqlpointers.com/2006/11/scenario-to-ponder-11.html?showComment=1166682780000#c6204125679916479589' title=''/><author><name>Omnibuzz</name><uri>http://www.blogger.com/profile/04342835880399785393</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.sqlpointers.com/2006/11/scenario-to-ponder-11.html' ref='tag:blogger.com,1999:blog-29286778.post-6324807287672434139' source='http://www.blogger.com/feeds/29286778/posts/default/6324807287672434139' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-817797350'/></entry></feed>
