 




<?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: Convert and Expand Field through SQL/400</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/convert-and-expand-field-through-sql400/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/convert-and-expand-field-through-sql400/</link>
	<description></description>
	<lastBuildDate>Tue, 21 May 2013 03:16:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: tomliotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/convert-and-expand-field-through-sql400/#comment-68967</link>
		<dc:creator>tomliotta</dc:creator>
		<pubDate>Mon, 12 Oct 2009 23:45:40 +0000</pubDate>
		<guid isPermaLink="false">#comment-68967</guid>
		<description><![CDATA[If you want to alter the database structure, it can&#039;t be done directly against the current tables. SQL will block attempts to alter numeric columns to character and vice versa.

But, a SQL VIEW can present numeric columns as character and vice versa. This could let you create VIEWs that present all of the columns in a common format. Once you are satisfied with the format, you can create new tables with the desired format and populate it with the data from the original tables.

Existing programming probably has programming that does these conversions. That programming would need to be changed to honor the new formats.

Other conversions can be done against live tables when they data types allow it. For example, you change a CHAR(8) column to CHAR(10) or you can change a CHAR() to a VARCHAR(). You can&#039;t change both length and datatype in a single operation; it would take two ALTERs to go from CHAR(10) to VARCHAR(20) for example.

Another way to CAST a 4-digit NUMERIC to CHAR(4) with leading zeroes:
&lt;pre&gt;
CAST(  RIGHT(&#039;0000&#039; CONCAT VARCHAR(numeric_col),4)) AS CHAR(4)) AS NewChar4
&lt;/pre&gt;
Tom]]></description>
		<content:encoded><![CDATA[<p>If you want to alter the database structure, it can&#8217;t be done directly against the current tables. SQL will block attempts to alter numeric columns to character and vice versa.</p>
<p>But, a SQL VIEW can present numeric columns as character and vice versa. This could let you create VIEWs that present all of the columns in a common format. Once you are satisfied with the format, you can create new tables with the desired format and populate it with the data from the original tables.</p>
<p>Existing programming probably has programming that does these conversions. That programming would need to be changed to honor the new formats.</p>
<p>Other conversions can be done against live tables when they data types allow it. For example, you change a CHAR(8) column to CHAR(10) or you can change a CHAR() to a VARCHAR(). You can&#8217;t change both length and datatype in a single operation; it would take two ALTERs to go from CHAR(10) to VARCHAR(20) for example.</p>
<p>Another way to CAST a 4-digit NUMERIC to CHAR(4) with leading zeroes:</p>
<pre>
CAST(  RIGHT('0000' CONCAT VARCHAR(numeric_col),4)) AS CHAR(4)) AS NewChar4
</pre>
<p>Tom</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 6/8 queries in 0.012 seconds using memcached
Object Caching 269/270 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-21 04:27:35 -->