<?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: To write a stored procedure</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/to-write-a-stored-procedure/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/to-write-a-stored-procedure/</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jun 2013 03:04:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-write-a-stored-procedure/#comment-78062</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Thu, 10 Jun 2010 17:37:25 +0000</pubDate>
		<guid isPermaLink="false">#comment-78062</guid>
		<description><![CDATA[I would do this with a function that returns a table, as follows:

&lt;pre&gt;create function spf_ZipCodeCongDist()
returns @ziptable table (
	zip	varchar(9),
	cong	varchar(255)) 
as
begin
	declare @zip	varchar(9);
	declare @cong	varchar(255);
	declare @ipos	int;
	declare cur cursor for 
		select ZipCode, CongDist
		from ZipCode;
	open cur;
	fetch next from cur into @zip, @cong;
	while @@FETCH_STATUS = 0
	begin
		while @cong is not null
		begin
			set @ipos = charindex(&#039;&#124;&#039;,@cong);
			if @ipos &gt; 0
			begin
				insert into @ziptable values (@zip, left(@cong, @ipos-1));
				set @cong = substring(@cong, @ipos+1, 255);
			end
			else
			begin
				insert into @ziptable values (@zip, @cong);
				set @cong = null;
			end;
		end;
		fetch next from cur into @zip, @cong;
	end;
	close cur;
	deallocate cur;
	return;
end;&lt;/pre&gt;

You can then query it to return your temp table as:

&lt;pre&gt;select * from spf_ZipCodeCongDist();&lt;/pre&gt;

Or, use it in a join, like:

&lt;pre&gt;select ...
from myTable mt
join spf_ZipCodeCongDist() zd on zd.zip = mt.zipcode
...&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>I would do this with a function that returns a table, as follows:</p>
<pre>create function spf_ZipCodeCongDist()
returns @ziptable table (
	zip	varchar(9),
	cong	varchar(255)) 
as
begin
	declare @zip	varchar(9);
	declare @cong	varchar(255);
	declare @ipos	int;
	declare cur cursor for 
		select ZipCode, CongDist
		from ZipCode;
	open cur;
	fetch next from cur into @zip, @cong;
	while @@FETCH_STATUS = 0
	begin
		while @cong is not null
		begin
			set @ipos = charindex('|',@cong);
			if @ipos &gt; 0
			begin
				insert into @ziptable values (@zip, left(@cong, @ipos-1));
				set @cong = substring(@cong, @ipos+1, 255);
			end
			else
			begin
				insert into @ziptable values (@zip, @cong);
				set @cong = null;
			end;
		end;
		fetch next from cur into @zip, @cong;
	end;
	close cur;
	deallocate cur;
	return;
end;</pre>
<p>You can then query it to return your temp table as:</p>
<pre>select * from spf_ZipCodeCongDist();</pre>
<p>Or, use it in a join, like:</p>
<pre>select ...
from myTable mt
join spf_ZipCodeCongDist() zd on zd.zip = mt.zipcode
...</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: sprocedure</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-write-a-stored-procedure/#comment-78008</link>
		<dc:creator>sprocedure</dc:creator>
		<pubDate>Wed, 09 Jun 2010 18:53:03 +0000</pubDate>
		<guid isPermaLink="false">#comment-78008</guid>
		<description><![CDATA[oaky not a sp but a query I am looking for]]></description>
		<content:encoded><![CDATA[<p>oaky not a sp but a query I am looking for</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sprocedure</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-write-a-stored-procedure/#comment-78007</link>
		<dc:creator>sprocedure</dc:creator>
		<pubDate>Wed, 09 Jun 2010 18:52:33 +0000</pubDate>
		<guid isPermaLink="false">#comment-78007</guid>
		<description><![CDATA[Okay here is what I am looking for
 
1. I have two tables Zipcode and a temp .
2. Zipcode has many columns along with Zipcode and CongDist
3. I need a temp table to store only Zipcode and CongDist
4. They was the values are stored in Zipcode table is Zipcode = 44819 and CongDist = 15&#124;13&#124;14
5. So what it means is Zipcode 44819 has 3 CongDist
6. I want to seperate each CongDist as a seperate entry in temp table
7. So the way it should store in temp table is each entry for 44819 and 15, 44819 and 13, 44819 and 14
 
Thanks]]></description>
		<content:encoded><![CDATA[<p>Okay here is what I am looking for</p>
<p>1. I have two tables Zipcode and a temp .<br />
2. Zipcode has many columns along with Zipcode and CongDist<br />
3. I need a temp table to store only Zipcode and CongDist<br />
4. They was the values are stored in Zipcode table is Zipcode = 44819 and CongDist = 15|13|14<br />
5. So what it means is Zipcode 44819 has 3 CongDist<br />
6. I want to seperate each CongDist as a seperate entry in temp table<br />
7. So the way it should store in temp table is each entry for 44819 and 15, 44819 and 13, 44819 and 14</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/to-write-a-stored-procedure/#comment-78006</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 09 Jun 2010 18:46:24 +0000</pubDate>
		<guid isPermaLink="false">#comment-78006</guid>
		<description><![CDATA[Yes, more details are needed.

You might want to post some example data as well.]]></description>
		<content:encoded><![CDATA[<p>Yes, more details are needed.</p>
<p>You might want to post some example data as well.</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.057 seconds using memcached
Object Caching 309/315 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-20 03:33:27 -->