1

Topic: String concatenation - as is better provide that one of items can to be NULL?

I want to add the elementary calculated column.
All calculation consists in blinding through a gap of value from several columns of the same table, and last in brackets.

ALTER TABLE test ADD user_title AS f4 + ' ' +f2 + ' ' +f7 + ' (' +comment + ') ';

With columns f * problems are not present, they NOT NULL so . it is not required. And here the column comment can be (and often enough and happens) equal NULL.
If in the last it is empty, it is necessary that it first of all did not spoil result, and " a gap and empty brackets " too it is not necessary to us at all.
The first thought which went at once in :

ALTER TABLE test ADD user_title AS f4 + ' ' +f2 + ' ' +f7+ISNULL (' (' +comment + ') ', ");

As though... The Line concatenated with NULL gives NULL, and ISNULL () in that case catches and substitutes  for blank line. All ok?
But I here reflected - and how it will be for the server? Can eat other decision which or is simple faster or in something the friend it is better for request scheduling?
It is possible and here so:

ALTER TABLE test ADD user_title AS f4 + ' ' +f2 + ' ' +f7+COALESCE (' (' +comment + ') ', ");

And here so too it is possible:

ALTER TABLE test ADD user_title AS f4 + ' ' +f2 + ' ' +f7+CASE WHEN comment IS NULL THEN "ELSE ' (' +comment + ') ' END;

And figs knows how many still methods it is possible to concoct at desire...
Prompt, how it will be better and why?

2

Re: String concatenation - as is better provide that one of items can to be NULL?

wrote:

Prompt, how it will be better and why?

At me other question arose - and what for so to do? It would be desirable to splice some fields in one - write view and there glue that you want to what you want.

3

Re: String concatenation - as is better provide that one of items can to be NULL?

System necessity. But a question not in it.
[sub] Or it is absolutely strong the big difference where it will be - in view or in calculated? [/sub]

4

Re: String concatenation - as is better provide that one of items can to be NULL?

wrote:

as it will be better

than Obasaljutno .

5

Re: String concatenation - as is better provide that one of items can to be NULL?

CONCAT