<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQL select loop list?</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/select-loop-list/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/select-loop-list/</link>
	<description></description>
	<lastBuildDate>Wed, 19 Jun 2013 09:51:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-loop-list/#comment-67922</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 09 Sep 2009 19:30:53 +0000</pubDate>
		<guid isPermaLink="false">#comment-67922</guid>
		<description><![CDATA[Dynamic SQL would be needed for that.

Something like this:

&lt;pre&gt;declare @counter int
declare @sql varchar(200)
	set @counter = 0
	set @sql = &#039;&#039;
	while @counter &lt; 10
	begin
	  set @counter = @counter + 1
	  if @counter &gt; 1
		set @sql = @sql + &#039; UNION &#039;
	  set @sql = @sql + &#039;SELECT id,f&#039;+cast(@counter as varchar(2))+&#039;,&#039;&#039;f&#039;+cast(@counter as varchar(2))+&#039;&#039;&#039; FROM table_x&#039;
	end
	execute (@sql)&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Dynamic SQL would be needed for that.</p>
<p>Something like this:</p>
<pre>declare @counter int
declare @sql varchar(200)
	set @counter = 0
	set @sql = ''
	while @counter &lt; 10
	begin
	  set @counter = @counter + 1
	  if @counter &gt; 1
		set @sql = @sql + ' UNION '
	  set @sql = @sql + 'SELECT id,f'+cast(@counter as varchar(2))+',''f'+cast(@counter as varchar(2))+''' FROM table_x'
	end
	execute (@sql)</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: meandyou</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-loop-list/#comment-67897</link>
		<dc:creator>meandyou</dc:creator>
		<pubDate>Wed, 09 Sep 2009 15:53:55 +0000</pubDate>
		<guid isPermaLink="false">#comment-67897</guid>
		<description><![CDATA[let me see if I have this straight...

table with these columns :
  ID
  F1
  F2
  F3
  etc

and you want a result like:
  value_of_ID  F1_value  name_of_F1
  value_of_ID  F2_value  name_of_F2
  value_of_ID  F3_value  name_of_F3

 
answer:
  SELECT ID, F1, &quot;F1&quot; FROM table
UNION
  SELECT ID, F2, &quot;F2&quot; FROM table
UNION
  etc

Part 2, can you &quot;loop through it&quot; by only supplying F1, F2, etc  ?

Without some sort of code around your SQL, I cannot think of a way to &quot;loop&quot;.  By some sort of code, I am referring to COBOL, REXX, or even some of the &quot;scripting&quot; languages.]]></description>
		<content:encoded><![CDATA[<p>let me see if I have this straight&#8230;</p>
<p>table with these columns :<br />
  ID<br />
  F1<br />
  F2<br />
  F3<br />
  etc</p>
<p>and you want a result like:<br />
  value_of_ID  F1_value  name_of_F1<br />
  value_of_ID  F2_value  name_of_F2<br />
  value_of_ID  F3_value  name_of_F3</p>
<p>answer:<br />
  SELECT ID, F1, &#8220;F1&#8243; FROM table<br />
UNION<br />
  SELECT ID, F2, &#8220;F2&#8243; FROM table<br />
UNION<br />
  etc</p>
<p>Part 2, can you &#8220;loop through it&#8221; by only supplying F1, F2, etc  ?</p>
<p>Without some sort of code around your SQL, I cannot think of a way to &#8220;loop&#8221;.  By some sort of code, I am referring to COBOL, REXX, or even some of the &#8220;scripting&#8221; languages.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.036 seconds using memcached
Object Caching 281/287 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-19 10:04:30 -->