<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Get Answer in Float When Dividing of Two Integer</title>
	<atom:link href="http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Darren</title>
		<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/#comment-53922</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Tue, 21 Jul 2009 14:23:26 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1185#comment-53922</guid>
		<description>This has caught me many times...
Putting the 1.0 at the beginning of the line makes a difference:

declare @a int,@b int,@c float
set @a=1
set @b=2

select @a/@b - Result 0
select @a/@b*1.0 - Result 0.0
select 1.0*@a/@b - Result 0.500000</description>
		<content:encoded><![CDATA[<p>This has caught me many times&#8230;<br />
Putting the 1.0 at the beginning of the line makes a difference:</p>
<p>declare @a int,@b int,@c float<br />
set @a=1<br />
set @b=2</p>
<p>select @a/@b &#8211; Result 0<br />
select @a/@b*1.0 &#8211; Result 0.0<br />
select 1.0*@a/@b &#8211; Result 0.500000</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Puzzle - Solution - Computed Columns Datatype Explanation Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/#comment-43346</link>
		<dc:creator>SQL SERVER - Puzzle - Solution - Computed Columns Datatype Explanation Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Mon, 29 Sep 2008 01:31:40 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1185#comment-43346</guid>
		<description>[...] SQL SERVER - Get Answer in Float When Dividing of Two Integer SQL SERVER - Puzzle - Computed Columns Datatype Explanation SQL SERVER - Puzzle - Solution - Computed Columns Datatype Explanation [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER &#8211; Get Answer in Float When Dividing of Two Integer SQL SERVER &#8211; Puzzle &#8211; Computed Columns Datatype Explanation SQL SERVER &#8211; Puzzle &#8211; Solution &#8211; Computed Columns Datatype Explanation [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marek Śliwiński</title>
		<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/#comment-43332</link>
		<dc:creator>Marek Śliwiński</dc:creator>
		<pubDate>Sun, 28 Sep 2008 09:39:25 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1185#comment-43332</guid>
		<description>Thanks guys, you make a nice duet together :)
Very interesting about this precedence.</description>
		<content:encoded><![CDATA[<p>Thanks guys, you make a nice duet together :)<br />
Very interesting about this precedence.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Puzzle - Computed Columns Datatype Explanation Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/#comment-43311</link>
		<dc:creator>SQL SERVER - Puzzle - Computed Columns Datatype Explanation Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Sat, 27 Sep 2008 01:31:10 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1185#comment-43311</guid>
		<description>[...] 27, 2008 by pinaldave    Yesterday I wrote post about SQL SERVER - Get Answer in Float When Dividing of Two Integer. I received excellent comment from SQL Server MVP Jacob Sebastian. Jacob has clearified the concept [...]</description>
		<content:encoded><![CDATA[<p>[...] 27, 2008 by pinaldave    Yesterday I wrote post about SQL SERVER &#8211; Get Answer in Float When Dividing of Two Integer. I received excellent comment from SQL Server MVP Jacob Sebastian. Jacob has clearified the concept [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry Hung</title>
		<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/#comment-43292</link>
		<dc:creator>Jerry Hung</dc:creator>
		<pubDate>Fri, 26 Sep 2008 14:23:07 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1185#comment-43292</guid>
		<description>Sometimes I get lazy and just do 
field = int column A / int column B * 1.0

Then I *think* I get float back</description>
		<content:encoded><![CDATA[<p>Sometimes I get lazy and just do<br />
field = int column A / int column B * 1.0</p>
<p>Then I *think* I get float back</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/#comment-43281</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Fri, 26 Sep 2008 10:14:35 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1185#comment-43281</guid>
		<description>Thank you Jacob,

I like your additional explanation. I just realize after reading your explanation that I should include your explanation in the post itself so it is visible to everybody right away. 

Also this has brought another idea in my mind that when creating calculated field the same scenario happens. E.g. When we create calculated field from additions of INT it will give us final calculated field as INT. If we want that in another datatype we should have either follow your suggestion or CAST them.

Regards,
Pinal</description>
		<content:encoded><![CDATA[<p>Thank you Jacob,</p>
<p>I like your additional explanation. I just realize after reading your explanation that I should include your explanation in the post itself so it is visible to everybody right away. </p>
<p>Also this has brought another idea in my mind that when creating calculated field the same scenario happens. E.g. When we create calculated field from additions of INT it will give us final calculated field as INT. If we want that in another datatype we should have either follow your suggestion or CAST them.</p>
<p>Regards,<br />
Pinal</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob sebastian</title>
		<link>http://blog.sqlauthority.com/2008/09/26/sql-server-division-by-float/#comment-43276</link>
		<dc:creator>Jacob sebastian</dc:creator>
		<pubDate>Fri, 26 Sep 2008 09:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1185#comment-43276</guid>
		<description>Nice post and something that is very much useful in the day-to-day programming life.

Just wanted to add to what is already explained, that, SQL Server automatically does a cast to the data type having the highest precedence. So the result of INT and INT will be INT, but INT and FLOAT will be FLOAT because FLOAT has a higher precedence. If you want a different data type, you need to do an EXPLICIT cast.

For example:

SELECT 100/3 AS Result
/*
Result
-----------
33
*/

SELECT 100/3.0 AS Result
/*
Result
---------------------------------------
33.333333
*/

The precedence of each data type is documented here: http://msdn.microsoft.com/en-us/library/ms190309(SQL.90).aspx</description>
		<content:encoded><![CDATA[<p>Nice post and something that is very much useful in the day-to-day programming life.</p>
<p>Just wanted to add to what is already explained, that, SQL Server automatically does a cast to the data type having the highest precedence. So the result of INT and INT will be INT, but INT and FLOAT will be FLOAT because FLOAT has a higher precedence. If you want a different data type, you need to do an EXPLICIT cast.</p>
<p>For example:</p>
<p>SELECT 100/3 AS Result<br />
/*<br />
Result<br />
&#8212;&#8212;&#8212;&#8211;<br />
33<br />
*/</p>
<p>SELECT 100/3.0 AS Result<br />
/*<br />
Result<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
33.333333<br />
*/</p>
<p>The precedence of each data type is documented here: <a href="http://msdn.microsoft.com/en-us/library/ms190309(SQL.90).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms190309(SQL.90).aspx</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
