Inconsistency in query result "isnull (column, '') returns a space"

0

During the process of producing a solution in C # records were saved forming a "folio" with a literal, a cell value and an id

'C'+ISNULL(Columna1,'')+Columna2

Example of result:

C96
CX85

The queries have not changed, the same database engine is still used (MSSQL server 2008) but now the same query brings the following difference:

'C'+ISNULL(Columna1,'')+Columna2
C 96

I do not understand why ISNULL(Columna1,'') returns a space (I already make sure that the column actually has NULL ). I know that you can solve the problem by adding LTRIM or RTRIM , however I would like to know why this change.

    
asked by German AT 27.07.2017 в 17:43
source

2 answers

0

If Column 1 in the test period was created with varchar (1), it is currently nchar (1), this would make the difference, to the extent that if it were nchar (10) and it had a NULL saved, the result of this query would throw 10 spaces:

'C'+ISNULL(Columna1,'')+Columna2
C          96
    
answered by 27.07.2017 / 18:08
source
0

Try using

'C'+TRIM(ISNULL(Columna1,''))+Columna2

Column1 may have a space, or Column2 may start with a space. In this second case, try

'C'+TRIM(ISNULL(Columna1,''))+TRIM(Columna2)

If it goes well, then one of the columns has spaces.

Also try the CONCAT function

CONCAT('C',ISNULL(Columna1,''),Columna2)

and if it still comes out with spaces add TRIM to the second and third parameters.

    
answered by 27.07.2017 в 17:52