﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Tom Thomson  / Type conversions and Nulls / 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>Sat, 25 May 2013 21:39:12 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]David Conn (3/6/2013)[/b][hr]C. This was my first encounter with uninitialised variables.[/quote]Thanks. I am pretty sure that aspect of C "fell off my memory queue" a long time ago :-P[quote]At least in T-SQL we can now give a Value on the Declare statement.[/quote]I like that too. We didn't have to worry about garbage in an uninitialized variable but that piece always seemed like one of the more obvious gaps in the language. Now that it is there the language feels that much more fluid and aligned with most of the other languages I work with, which is nice.</description><pubDate>Wed, 06 Mar 2013 23:42:34 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>C. This was my first encounter with uninitialised variables. When I declare an Integer for example I expect its value to be 0.At least in T-SQL we can now give a Value on the Declare statement.</description><pubDate>Wed, 06 Mar 2013 23:29:38 GMT</pubDate><dc:creator>David Conn</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]David Conn (3/6/2013)[/b][hr]The ones that don't tend to just leave the Variable with whatever is in its memory location.[/quote]Yikes, not sure I know (or knew or remember) which might do that. To which were you referring?</description><pubDate>Wed, 06 Mar 2013 23:20:35 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>I got caught by the Null. I work as a Programmer more often than not where some Languages automatically initialise a Variable at declaration time. The ones that don't tend to just leave the Variable with whatever is in its memory location. I would prefer Null as a default in these instances rather than garbage.</description><pubDate>Wed, 06 Mar 2013 23:12:38 GMT</pubDate><dc:creator>David Conn</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Wow, my first really wrong answer. I knew about CASE's type inferral, just forgot. Thanks for the exceptionally good question.</description><pubDate>Tue, 26 Feb 2013 06:44:35 GMT</pubDate><dc:creator>sqlcentral-bugmenot</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]Rob Schripsema (2/5/2013)[/b][hr]Great question, TomI [b]almost[/b] wish you had thrown in an option of '2012-04-01 10:00:00.000' to spice up the thinking a bit more. Of course, then I probably would have gotten it wrong....[/quote]+1 to thatNice question.</description><pubDate>Mon, 11 Feb 2013 07:14:18 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Thanks for the question!</description><pubDate>Thu, 07 Feb 2013 01:26:54 GMT</pubDate><dc:creator>Christian Buettner-167247</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Nice question - thanks, Tom!</description><pubDate>Wed, 06 Feb 2013 11:08:19 GMT</pubDate><dc:creator>Revenant</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Excellent question, Tom, and even better explanation.</description><pubDate>Wed, 06 Feb 2013 10:07:38 GMT</pubDate><dc:creator>EL Jerry</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Good question, thank you for writing it!</description><pubDate>Wed, 06 Feb 2013 07:52:15 GMT</pubDate><dc:creator>mtassin</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Easy one for me .</description><pubDate>Wed, 06 Feb 2013 03:04:09 GMT</pubDate><dc:creator>kapfundestanley</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Curse you Precedence!always the one that I forget about, ah well :)</description><pubDate>Tue, 05 Feb 2013 21:44:05 GMT</pubDate><dc:creator>David in .AU</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]Olga B (2/5/2013)[/b][hr]Well, the good news is, I got NULLs down pat. The less good news is, I didn't even stop to think about type precedence. Conclusion - time for more coffee.[/quote] +1 on that.And as for the collation specification, I figured that was just Tom's QOD signature since most of his contributions that I recall had to do with that.Overall, very good one.</description><pubDate>Tue, 05 Feb 2013 19:10:03 GMT</pubDate><dc:creator>john.arnott</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Well, the good news is, I got NULLs down pat. The less good news is, I didn't even stop to think about type precedence. Conclusion - time for more coffee.</description><pubDate>Tue, 05 Feb 2013 17:54:13 GMT</pubDate><dc:creator>Olga B</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Nice question and explanation. Thanks Tom.</description><pubDate>Tue, 05 Feb 2013 16:05:50 GMT</pubDate><dc:creator>KWymore</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]chgn01 (2/5/2013)[/b][hr]Please try:declare @k int;select  case when @k=0 OR NOT (@k = 0)    then cast(0 as date)    else cast('2012-04-01T10:00:00' as datetime)  end as [when] ;[/quote]Well, that will fail with an error at cast(0 as date)[quote]anddeclare @k int;select  case when @k=0 OR NOT (@k = 0)    then cast('04/01/2012T10:00:00' as date)    else cast('2012-04-01T10:00:00' as datetime)  end as [when] ;[/quote]Well, it seems quite reasonable that cast('2012-04-01T10:00:00' as datetime) should deliver    2012-04-01 10:00:00.000</description><pubDate>Tue, 05 Feb 2013 13:52:36 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Great question, TomI [b]almost[/b] wish you had thrown in an option of '2012-04-01 10:00:00.000' to spice up the thinking a bit more. Of course, then I probably would have gotten it wrong....</description><pubDate>Tue, 05 Feb 2013 12:32:32 GMT</pubDate><dc:creator>Rob Schripsema</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Please try:declare @k int;select  case when @k=0 OR NOT (@k = 0)    then cast(0 as date)    else cast('2012-04-01T10:00:00' as datetime)  end as [when] ;anddeclare @k int;select  case when @k=0 OR NOT (@k = 0)    then cast('04/01/2012T10:00:00' as date)    else cast('2012-04-01T10:00:00' as datetime)  end as [when] ;</description><pubDate>Tue, 05 Feb 2013 09:59:31 GMT</pubDate><dc:creator>chgn01</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Thanks Tom.  After a number of controversial questions and explanations it is great to have one that makes you think and is right on target.+1</description><pubDate>Tue, 05 Feb 2013 09:55:52 GMT</pubDate><dc:creator>Miles Neale</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]Hugo Kornelis (2/5/2013)[/b][hr]Very good question, and an awesome explanation. (Apart from one small type that you probably put in deliberately to prove that you're still human).Thanks, Tom![/quote]+1When I started reading language and collation settings I was sure it was going to be one of those controversial questions. Really glad to see it wasn't!Thanks a lot, Tom! :-)</description><pubDate>Tue, 05 Feb 2013 09:22:05 GMT</pubDate><dc:creator>Primo Dang</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>A great qotd and explanation. Had thunk it many times before getting it right... :-)</description><pubDate>Tue, 05 Feb 2013 09:21:10 GMT</pubDate><dc:creator>venkat9.sql</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]Dineshbabu (2/4/2013)[/b][hr]Nice one Tom. Tom I need ask you one thing. Is there any collation setting to affect the result of today's question ?[/quote]Raghu has answered that one at least as well as I could.  I think the collation got described because there was a different question fro which the collation mattered very much, and I was cutting and pasting.  Similarly, the database name came from a question that had a "USE" statement for that db.  Careless cutting and pasting, but those things may have helped get people to stop and think so I don't feel guilty about it. ;-)</description><pubDate>Tue, 05 Feb 2013 08:27:37 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]john.moreno (2/4/2013)[/b][hr]I got it right, but I wish the date wasn't April Fools day -- it adds a bit of "meta" distraction to the question.Is it ha, ha fooled you if you pick it, or ha, ha should have picked this?  Either way, an unwelcome distraction from an otherwise nice question.[/quote]Originally I had 28 December, but then thought "oh, people will expect a trick if I use that date" so changed it.[quote]PS There was some sort of typo or word missing trom the explanation.[/quote]Yes, there was: "there" instead of "none", a very silly typo.  I started with "if there isn't one of the tests which delivers true" or something similarly verbose and rotten style with a double negative like that, and decided to change it to "if none of the tests delivers true" and screwed up the edit.</description><pubDate>Tue, 05 Feb 2013 08:23:11 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]bitbucket-25253 (2/4/2013)[/b][hr]nice question .. glad to see you contributing to the QOD to allow others to learn what you can teach.[/quote]I've got a long way to catch up with your number of questions, Ron, and even further to go before my average question quality reaches any where near as high as yours.</description><pubDate>Tue, 05 Feb 2013 08:18:05 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Great question, thanks Tom!</description><pubDate>Tue, 05 Feb 2013 07:39:57 GMT</pubDate><dc:creator>sestell1</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Very nice question, and excellent explanation.</description><pubDate>Tue, 05 Feb 2013 07:36:46 GMT</pubDate><dc:creator>Mark DeMoss</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Great question Tom. My only complaint is that it was so well written there is no room for ambiguity or misinterpretation. ;-)</description><pubDate>Tue, 05 Feb 2013 07:08:55 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Good question and explanation Tom.Thanks,</description><pubDate>Tue, 05 Feb 2013 06:55:50 GMT</pubDate><dc:creator>jagpatel9</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Great question and awesome explanation.</description><pubDate>Tue, 05 Feb 2013 06:52:42 GMT</pubDate><dc:creator>Dana Medley</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Nice job with the question Tom.</description><pubDate>Tue, 05 Feb 2013 06:10:29 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Excellent question and explanation - several issues covered in one go - thank you.</description><pubDate>Tue, 05 Feb 2013 05:34:18 GMT</pubDate><dc:creator>sipas</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>[quote][b]ldorian81 (2/5/2013)[/b][hr]I knew there was a trick to this one,really good question thanks :)[/quote]Yes, I saw the NULL issue immediately, and then hit one of the checkboxes. Didn't even stop chewing my breakfast to contemplate datatype precedence. Nicely posed and explained.</description><pubDate>Tue, 05 Feb 2013 04:58:32 GMT</pubDate><dc:creator>Thomas Abraham</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Great question Tom, with a couple of wee pitfalls to lead the unwary, fortunately I had remembered my wits today. Superb explanation too.:-D</description><pubDate>Tue, 05 Feb 2013 04:48:46 GMT</pubDate><dc:creator>DugyC</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Excellent question, Thanks so much.</description><pubDate>Tue, 05 Feb 2013 04:11:14 GMT</pubDate><dc:creator>(Bob Brown)  </dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>nice question. and superb explanation.Thanks,  Tom[i]***ManikGo fast as possible[/i]</description><pubDate>Tue, 05 Feb 2013 03:59:10 GMT</pubDate><dc:creator>manik123</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Good one. Thanks for this. +1</description><pubDate>Tue, 05 Feb 2013 03:07:58 GMT</pubDate><dc:creator>Yogeshwar Phull</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Very good question, and an awesome explanation. (Apart from one small type that you probably put in deliberately to prove that you're still human).Thanks, Tom!</description><pubDate>Tue, 05 Feb 2013 02:42:32 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Thanks for the question Tom, nice reminder of the basics.</description><pubDate>Tue, 05 Feb 2013 02:35:03 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>I knew there was a trick to this one,really good question thanks :)</description><pubDate>Tue, 05 Feb 2013 02:12:01 GMT</pubDate><dc:creator>ldorian81</dc:creator></item><item><title>RE: Type conversions and Nulls</title><link>http://www.sqlservercentral.com/Forums/Topic1415558-2681-1.aspx</link><description>Good question, thanks Tom</description><pubDate>Tue, 05 Feb 2013 01:31:44 GMT</pubDate><dc:creator>Stewart "Arturius" Campbell</dc:creator></item></channel></rss>