TSQL variables and null
It has been quite sometime since I actually coded TSQL. So I had to kind of brush up the hidden knowledge over the weekend when I wrote a small stored proc for a personal project I am working on.
(expect to see something in Codeplex, if I can get it finished before the new year)
I declared a variable and wrote out some code as follow:
declare @tempstring as nvarchar(max)
<More code here>
select @tempstring=@tempstring + ' ' + @word
I was kind of left scratching my head as @tempstring always seem to end up being empty, even when @word did have some data.
Then I remembered something from my start up SQL classes... anything+null is always null. So I initialized @tempstring to an empty string and viola, there the data was, correct and ready to use.
Having been working so much in VB that it actually took me quite a while to figure out those small klinks that are specific to TSQL.
This is the kind of situation that may really affect someone moving from C# to VB or vice versa too. :)






