sql server - ISNULL returning truncated string -
i'm having unusual issue:
declare @enabledclients table(id int); --some clients have setting enabled default declare @enabled nvarchar(10); insert @enabledclients (id) select [id] dbo.client name in ('foo', 'bar'); as loop through each client, want set @enabled true or false:
while @clientid not null begin set @enabled = isnull((select 'true' @enabledclients id = @clientid), 'false'); ... set @clientid = (select min(clientid) dbo.client id > @clientid); end if client 'foo' or 'bar', @enabled 'true' expected. if not, @enabled 'fals'. not 'false', expect, 4-character string 'fals'. why be?
isnull returns result datatype of first parameter. string literal 'true' treated varchar(4)
you can use coalesce desired result will execute query twice.
you can stick isnull , cast literal in first query varchar(5) avoid issue.
cast('true' varchar(5))
Comments
Post a Comment