Jeff Moden wrote:
Yes, I also thought about it, but the following example shows it doesn't matter - SQL Server implicitly converts NULL to the correct type, no?
DECLARE @t AS TABLE (A INT);
INSERT INTO @t
VALUES( CAST(NULL AS VARCHAR(1)))
SELECT * FROM @t
First of all, having a VARCHAR(1) is a really bad idea. It takes two additional bytes for SQL Server to mark the column size. In the case above, I agree... for inserts, there's no need to cast a NULL to anything unless you're using SELECT/INTO and are using that to define what the column should actually be.
I'd stick with varchar for this specific use. I've just had too many odd results when a fixed char was involved, even though varchar has higher precedence. As to performance, this is a one-time value, so the performance "hit" will be miniscule.
However, for a table column, definitely use char(1) rather than varchar(1), due to performance, but within characters expressions, personally I stick to varchar.
SQL DBA,SQL Server MVP(07, 08, 09) Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial: "If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them."