<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: How do I create a SQL Server 2000 'View' programmatically, using Visual Basic?</title>
	<link>http://ask.metafilter.com/100681/How-do-I-create-a-SQL-Server-2000-View-programmatically-using-Visual-Basic/</link>
	<description>Comments on Ask MetaFilter post How do I create a SQL Server 2000 'View' programmatically, using Visual Basic?</description>
	<pubDate>Tue, 02 Sep 2008 05:00:47 -0800</pubDate>
	<lastBuildDate>Tue, 02 Sep 2008 05:00:47 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: How do I create a SQL Server 2000 &apos;View&apos; programmatically, using Visual Basic?</title>
		<link>http://ask.metafilter.com/100681/How-do-I-create-a-SQL-Server-2000-View-programmatically-using-Visual-Basic</link>	
		<description>I&apos;m working in Visual Basic (Access 2003, technically) with a SQL Server 2000 backend, and I believe I need to create a View dynamically...  I am very familiar with creating QueryDef&apos;s and Stored Procedures on the fly, but have never attempted to create a View in this manner...  My google-fu seems to be failing me at the moment..   &lt;br /&gt;&lt;br /&gt; Note:  The reason I need to create a view in this manner, is that I&apos;m running the same stored procedure many times, with different parameters.  By the end of the function, there will be a decent amount of overlapping data, which is unacceptable.  I&apos;d like to toss it all into a view as I go, so that I can pull out the distinct records at the end.&lt;br&gt;
&lt;br&gt;
If my logic is screwy, feel free to suggest an alternate approach!</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2008:site.100681</guid>
		<pubDate>Tue, 02 Sep 2008 04:26:10 -0800</pubDate>
		<dc:creator>Glendale</dc:creator>
		
			<category>vb6</category>
		
			<category>sql</category>
		
			<category>server</category>
		
			<category>program</category>
		
			<category>code</category>
		
	</item> <item>
		<title>By: orthogonality</title>
		<link>http://ask.metafilter.com/100681/How-do-I-create-a-SQL-Server-2000-View-programmatically-using-Visual-Basic#1463127</link>	
		<description>&lt;em&gt;&quot;By the end of the function, there will be a decent amount of overlapping data, which is unacceptable.&quot;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
Your function is throwing the data into a temp table, and you wish to create a view over the temp table? If the temp table&apos;s destroyed when the function exists, the data won&apos;t be in the view, you understand?&lt;br&gt;
&lt;br&gt;
But the basic answer to your question is that you create the view the same way you issue dynamic SQL queries. If you create a dynamic query like this: query( &quot;select 1, 2, 3 from table&quot;);  &lt;br&gt;
&lt;br&gt;
You create a view like this: query( &quot;create view view_name as select 1, 2, 3 from table&quot;);&lt;br&gt;
(Assuming your connection has create view permissions.)&lt;br&gt;
&lt;br&gt;
Can you more fully explain what you&apos;re trying to do?&lt;br&gt;
But if the table isn&apos;t a temp table, it&apos;s much easier to just create the view in the database once, and just query it.&lt;br&gt;
&lt;br&gt;
Is your problem that several runs of your function are logically connected, but are not related to earlier runs? Then use a run-number as a parameter to your function, and stick it in the table.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.100681-1463127</guid>
		<pubDate>Tue, 02 Sep 2008 05:00:47 -0800</pubDate>
		<dc:creator>orthogonality</dc:creator>
	</item><item>
		<title>By: mrbugsentry</title>
		<link>http://ask.metafilter.com/100681/How-do-I-create-a-SQL-Server-2000-View-programmatically-using-Visual-Basic#1463219</link>	
		<description>Or, as long as you don&apos;t have concurrence problems, you can create a temp table that will hold the ids of the records you want to save and make your view something like &lt;br&gt;
&lt;br&gt;
&lt;small&gt;&lt;br&gt;
&quot;SELECT * FROM myTable WHERE ID IN(SELECT ID FROM myTempTable)&quot;&lt;br&gt;
&lt;/small&gt;&lt;br&gt;
&lt;br&gt;
Your sprocs dump the id of the records you want to see into myTempTable.  If there are duplicate records, no big deal.&lt;br&gt;
&lt;br&gt;
Definitely hack-ish, but there is a time and a place for a hack.  We sometimes use this kind of thing for long running searches.&lt;br&gt;
&lt;br&gt;
Of course, you could also pull the data using a sproc, which would allow you to pass a search id parameter from the client: &lt;br&gt;
&lt;small&gt;&lt;br&gt;
&quot;SELECT * FROM myTable WHERE WHERE ID IN(SELECT ID FROM myTempTable WHERE SearchID = @SearchID)&quot;&lt;br&gt;
&lt;/small&gt;&lt;br&gt;
&lt;br&gt;
That way, you can keep your searches separate from your coworkers&apos; searches.  (With appropriate housekeeping code someplace to delete yesterday&apos;s searches).  Hackish?  Of course.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.100681-1463219</guid>
		<pubDate>Tue, 02 Sep 2008 07:21:31 -0800</pubDate>
		<dc:creator>mrbugsentry</dc:creator>
	</item>
	</channel>
</rss>
