tsql - SQL Server : coalesce, the part of string is missing -
i have code:
declare @results varchar(500) select @results = coalesce(@results+', ', '') + convert(varchar(12),k.t1) ( select '('+cast(count(distinct(g.roomid)) varchar) + ') '+ rt.classname t1 db_pms.guests g left join db_pms.roomtypes rt on rt.roomtypeid=g.roomtypeid g.groupid = 47 , g.status >= 0 group g.roomtypeid, rt.classname ) k select @results results
the part
select '('+ cast(count(distinct(g.roomid))as varchar) + ') '+ rt.classname t1 db_pms.guests g left join db_pms.roomtypes rt on rt.roomtypeid=g.roomtypeid g.groupid = 47 , g.status >= 0 group g.roomtypeid, rt.classname
returns
(1) Люкс (4) Полулюкс (2) Стандарт dbl (6) Стандарт twn (1) Стандарт+ twn
and after using
select @results = coalesce(@results + ', ', '') + convert(varchar(12),k.t1)
i
(1) Люкс (4) Полулюкс (2) Стандарт (6) Стандарт (1) Стандарт
as can see part of string column missing. can fix it?
your varchar(12)
small hold results, due way mysql (and sql server) counts length varchar. example, running query:
select length( 'Стандарт twn' )
will give length of 20! need increase length, , fine.
sql fiddle showing results: http://sqlfiddle.com/#!9/9eecb7d/5661/0
in sql server may wish consider use of nvarchar well.
Comments
Post a Comment