<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://petersap.nl/SybaseWiki/index.php?action=history&amp;feed=atom&amp;title=Sp_autoformat</id>
		<title>Sp autoformat - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://petersap.nl/SybaseWiki/index.php?action=history&amp;feed=atom&amp;title=Sp_autoformat"/>
		<link rel="alternate" type="text/html" href="http://petersap.nl/SybaseWiki/index.php?title=Sp_autoformat&amp;action=history"/>
		<updated>2026-04-04T20:48:26Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.24.2</generator>

	<entry>
		<id>http://petersap.nl/SybaseWiki/index.php?title=Sp_autoformat&amp;diff=1713&amp;oldid=prev</id>
		<title>Psap at 18:59, 17 July 2007</title>
		<link rel="alternate" type="text/html" href="http://petersap.nl/SybaseWiki/index.php?title=Sp_autoformat&amp;diff=1713&amp;oldid=prev"/>
				<updated>2007-07-17T18:59:31Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The sp_autoformat stored procedure, supplied by Sybase, can be used to format the output of a query into a more readable resultset. Here are a few example how you might use it, and a list of some common issues.&lt;br /&gt;
&lt;br /&gt;
==Sample 1==&lt;br /&gt;
When you run this query on ASE 15 it will produce really wide output.&lt;br /&gt;
&lt;br /&gt;
 select type,name from sysobjects&lt;br /&gt;
&lt;br /&gt;
Now try this and the result is much better to read:&lt;br /&gt;
&lt;br /&gt;
 select type,name into #temp from sysobjects&lt;br /&gt;
 exec sp_autoformat &amp;quot;#temp&amp;quot;&lt;br /&gt;
 drop table #temp&lt;br /&gt;
&lt;br /&gt;
==Sample 2==&lt;br /&gt;
You can also have sp_autoformat work on a subset of the #table you created:&lt;br /&gt;
&lt;br /&gt;
 select type,name into #temp from sybsystemprocs..sysobjects&lt;br /&gt;
 exec sp_autoformat &amp;quot;#temp&amp;quot;,@whereclause=&amp;quot;where type = 'U'&amp;quot;&lt;br /&gt;
 drop table #temp&lt;br /&gt;
&lt;br /&gt;
This sample in itself does not make much sense, but it demonstrates that you can use sp_autoformat easily into existing code that creates temporary tables.&lt;br /&gt;
&lt;br /&gt;
==Some notes==&lt;br /&gt;
* You must supply the word &amp;quot;where&amp;quot; into the @whereclause variable, otherwise sp_autoformat will crash. (This is not properly shown in the ISUG article of Q4 2006).&lt;br /&gt;
* All columns for the #temp table should be named (strictly spoken not an sp_autoformat issue). This sample will fail:&lt;br /&gt;
&lt;br /&gt;
 -- Will generate error&lt;br /&gt;
 select type,count(*) into #temp from sysobjects group by type&lt;br /&gt;
 exec sp_autoformat &amp;quot;#temp&amp;quot;&lt;br /&gt;
 drop table #temp&lt;br /&gt;
&lt;br /&gt;
 -- Will work&lt;br /&gt;
 select type,count(*) as cnt into #temp from sysobjects group by type&lt;br /&gt;
 exec sp_autoformat &amp;quot;#temp&amp;quot;&lt;br /&gt;
 drop table #temp&lt;br /&gt;
* Besides using the @whereclause variable, there is also the possiblity to use the @selectlist (to specify output columns) and @orderby (for sorting).&lt;br /&gt;
* Can create xml output like this:&lt;br /&gt;
 select min(name) as name into #name from sysobjects&lt;br /&gt;
 exec sp_autoformat &amp;quot;#name&amp;quot;,@fmtspecifier=&amp;quot;for xml&amp;quot;&lt;br /&gt;
 drop table #name&lt;br /&gt;
Please note that this requires that xml has been enabled (sp_configure &amp;quot;enable xml&amp;quot;) and that the output becomes wide again!&lt;br /&gt;
&lt;br /&gt;
[[Category:ASE]]&lt;/div&gt;</summary>
		<author><name>Psap</name></author>	</entry>

	</feed>