﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQLServerCentral.com Announcements / SQLServerCentral.com  / Implicit Conversions / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 15:38:04 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>good question with great discussion :-)</description><pubDate>Mon, 03 Dec 2012 23:24:52 GMT</pubDate><dc:creator>kapil_kk</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>ah-hah, thanks John, that makes a whole lot of sense!</description><pubDate>Fri, 15 Aug 2008 17:57:29 GMT</pubDate><dc:creator>Tao Klerks</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Tao,I think the difference is just in the wording of the error message.  My SQL 2000 instance gives: [code]Msg 245, Level 16, State 1, Line 1Syntax error converting the varchar value 'B' to a column of data type int.[/code]and my 2005 gives:[code]Msg 245, Level 16, State 1, Line 1Conversion failed when converting the varchar value 'B' to data type int.[/code]Note that both versions call it Msg 245, implying that it's the same error and the text has been corrected/clarified in the newer version.  It's not really a syntax error at all, but a conversion error at the time the UNION is attempted. </description><pubDate>Fri, 15 Aug 2008 17:54:40 GMT</pubDate><dc:creator>john.arnott</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Hmm, getting late to this, but I'm having difficulty accepting the answer provided here. Here is the exact result I received on a SQL Server 2000 instance:Server: Msg 245, Level 16, State 1, Line 1Syntax error converting the varchar value 'B' to a column of data type int.Note the [b]Syntax error[/b] - does this not fly in the face of all the explanations thus far??(or is this a SQL Server 2005-specific question / answer and I simply didn't read properly?)</description><pubDate>Fri, 15 Aug 2008 16:43:05 GMT</pubDate><dc:creator>Tao Klerks</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>[quote][b]john.arnott (5/6/2008)[/b][hr]Excellent question in that to understand the result, you have to step through the entire process.  --The statements compile.  --Each "select" is executed.--Then the two result sets are combined to effect the Union. That's where the error occurs.That's why even though the alpha character "B" was earlier in the code, the [b]execution[/b] tried to convert it to the higher precedence integer type to satisfy the column type forced by the later value "4". The compiler couldn't catch this as it won't look at the values, only the datatypes. If the character input had been a digit (in quotes), it would run.  This works:[code]select '3'union select 4[/code][/quote]good explanation,</description><pubDate>Wed, 07 May 2008 00:47:16 GMT</pubDate><dc:creator>shamshudheen</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Hm, the answer is kind of paradox.Either the "the varchar is converted to int" or an "error occurs". But not both.I would have preferred an answer like this:     An error occurs during conversion from varchar to int.But i should mostly blame myself for not reading the answer to the end...</description><pubDate>Tue, 06 May 2008 11:56:50 GMT</pubDate><dc:creator>Christian Buettner-167247</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Excellent question in that to understand the result, you have to step through the entire process.  --The statements compile.  --Each "select" is executed.--Then the two result sets are combined to effect the Union. That's where the error occurs.That's why even though the alpha character "B" was earlier in the code, the [b]execution[/b] tried to convert it to the higher precedence integer type to satisfy the column type forced by the later value "4". The compiler couldn't catch this as it won't look at the values, only the datatypes. If the character input had been a digit (in quotes), it would run.  This works:[code]select '3'union select 4[/code]</description><pubDate>Tue, 06 May 2008 09:13:20 GMT</pubDate><dc:creator>john.arnott</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>That will teach me for speed reading the answers - missed the (error results) at the end of answer two! So picked answer 3! My bad...(But at least I knew it wouldn't work!)Rodney</description><pubDate>Tue, 06 May 2008 03:48:52 GMT</pubDate><dc:creator>rodjkidd</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>I feel the same way, in addition note the wording:This is an example of an implicit conversion. In this case, an error is returned as the varchar is converted to an int, or an attempt is made, which returns an error. The int is of higher precedence than a varchar, so that is the order of conversions.What is it converted and when error says failed to convert and then you say varchar IS converted to an int and then you say OR  attempt is made?   Which one is it?</description><pubDate>Mon, 05 May 2008 16:13:47 GMT</pubDate><dc:creator>Sponge-592981</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>[quote][b]Trace Herrell (5/5/2008)[/b][hr]This will not compile in SQL 2005....Conversion failed when converting the varchar value 'B' to data type int.[/quote]On the contrary, it did compile but it encountered an error when it ran.  If you mistyped and put in "Skelect 'B' ..." it would not compile.  Conversion failure is a runtime error, in this case because a varchar 'B' can't be converted to int.  The compiler doesn't check to make sure you won't run into data type errors.</description><pubDate>Mon, 05 May 2008 13:27:09 GMT</pubDate><dc:creator>srienstr</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>This will not compile in SQL 2005....Conversion failed when converting the varchar value 'B' to data type int.</description><pubDate>Mon, 05 May 2008 12:40:19 GMT</pubDate><dc:creator>Trace Herrell-425305</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>[quote][b]Steve Jones - Editor (5/5/2008)[/b][hr]That is not a compilation error. It's a run-time error when a conversion occurs. There are very few compilation errors, mostly syntax issues.[/quote]In my humble opinion the answer [quote]The varchar is converted in int (error results)[/quote]  should have beenThe varchar is not converted into int (run time error results)Since this union statement will work (no run time error)select '10'     Union Select 4and this will compileCREATE PROCEDURE Dbo.OopsASselect 'B'     Union Select 4but will result in the run time error when invoked.Oh well looking back now .... I have gained knowledge from the QOD and that is its objective.Thanks Steve for making think even more</description><pubDate>Mon, 05 May 2008 09:13:11 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>AS previously stated: [quote][b]dunnjoe (5/5/2008)[/b][hr]That's why I feel answer b is not correct. Answer b says the value is converted to an int. The error message says the conversion failed. So, it appears to be a compilation error.[/quote]Unfortunately I came to the same conclusion ... the statement did NOT execute ... other than the error message[quote]Msg 245, Level 16, State 1, Line 1Conversion failed when converting the varchar value 'B' to data type int.[/quote]  There were NO values returned!!Still a good QOD just a bad wording of possible answers ... to the detriment of many of us</description><pubDate>Mon, 05 May 2008 08:56:20 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>That is not a compilation error. It's a run-time error when a conversion occurs. There are very few compilation errors, mostly syntax issues.</description><pubDate>Mon, 05 May 2008 08:29:30 GMT</pubDate><dc:creator>Steve Jones - SSC Editor</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>[quote][b]bvesperman (5/5/2008)[/b][hr]I agree that this doesn't work. I was pretty sure it wasn't going to do an implicit conversion. Then I cut and pasted it into a query and executed it. And I was proven right. It failed. No results were returned. An error was returned. It things like this that makes me not try to read or follow information from sites like this one. Is there a setting in MSSQL that allows implicit conversion? I hope not. My databases need to maintain data integrity, and if implicit conversions are happening I can't trust my databases.[/quote]Yes, implicit conversions happen.It's not a problem, if you know how they work.  Books Online has exact data on what they do and why and how.</description><pubDate>Mon, 05 May 2008 08:25:36 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>I agree that this doesn't work. I was pretty sure it wasn't going to do an implicit conversion. Then I cut and pasted it into a query and executed it. And I was proven right. It failed. No results were returned. An error was returned. It things like this that makes me not try to read or follow information from sites like this one. Is there a setting in MSSQL that allows implicit conversion? I hope not. My databases need to maintain data integrity, and if implicit conversions are happening I can't trust my databases.</description><pubDate>Mon, 05 May 2008 08:17:59 GMT</pubDate><dc:creator>bvesperman</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>That's why I feel answer b is not correct. Answer b says the value is converted to an int. The error message says the conversion failed. So, it appears to be a compilation error.</description><pubDate>Mon, 05 May 2008 08:03:04 GMT</pubDate><dc:creator>dunnjoe</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>This does not work on SQL Server 2005.  You get the following error message:"Msg 245, Level 16, State 1, Line 1Conversion failed when converting the varchar value 'B' to data type int."</description><pubDate>Mon, 05 May 2008 07:21:02 GMT</pubDate><dc:creator>William Vach</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>I have 2000, and it gave the "correct" result for me.</description><pubDate>Mon, 05 May 2008 06:56:10 GMT</pubDate><dc:creator>srienstr</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Perhaps I missed something...But I believe this works on SQL2000, but 2005.There was a change to the behavior of unions....ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/instsql9/html/47edefbd-a09b-4087-937a-453cd5c6e061.htm</description><pubDate>Mon, 05 May 2008 06:24:00 GMT</pubDate><dc:creator>Jason Miller-476791</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Simple but strong question. We require more this type of questions where you have to 'think' before answering. Before seeing Jeff's comment 'Average Question' :P, I thought it was 'good' question as the marks is '3' not the normal '1'. So I thought more than require. :hehe:</description><pubDate>Mon, 05 May 2008 02:04:13 GMT</pubDate><dc:creator>Anipaul</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>I agree... judging from some of the "Why am I getting this error" questions on the forum, implicit conversions to "bite" people a lot.  This "simple" question is a very good example of a lot of problems folks have with UNIONs and other places where columnar data is mixed to form a single column.</description><pubDate>Sun, 04 May 2008 10:07:53 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>I put it as 3 because I think implicit conversions cause a lot of issues, waste time, and I see a lot of questions on these. So it's important.I may go back and "re-rate" some questions, moving some 1s to 2s and 2s to 3s or 4s, trying to weight them a little more when you have to think. I'll adjust points for correct answers as well if I do.</description><pubDate>Sun, 04 May 2008 09:50:59 GMT</pubDate><dc:creator>Steve Jones - SSC Editor</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>3 Marks isn't bad or good... it means "average" and it is an "Average" question. :P</description><pubDate>Sun, 04 May 2008 09:30:04 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Why 3 marks for this question??</description><pubDate>Sun, 04 May 2008 01:20:16 GMT</pubDate><dc:creator>gbpthomas</dc:creator></item><item><title>Implicit Conversions</title><link>http://www.sqlservercentral.com/Forums/Topic494662-83-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/62806/"&gt;Implicit Conversions&lt;/A&gt;[/B]</description><pubDate>Sat, 03 May 2008 12:01:08 GMT</pubDate><dc:creator>Site Owners</dc:creator></item></channel></rss>