Ale B
Ale B

Reputation: 59

sql concatenation in SELECT

In the SELECT clause I have SELECT isnull(client,'')+'-'+isnull(supplier,''), is it ok to write GROUP BY client,supplier, or should I mandatorily write GROUP BY isnull(client,'')+'-'+isnull(supplier,'')?

Upvotes: 0

Views: 489

Answers (3)

amir akhnun
amir akhnun

Reputation: 13

You can directly say group by client, supplier

Please see sample data and result after running query.

sample

Upvotes: 0

SAS
SAS

Reputation: 4035

Just list the column names. You can verify this by executing it, and also look at execution plans to verify index usage.

GROUP BY client,supplier

Upvotes: 0

NotFound
NotFound

Reputation: 6157

It's better to GROUP BY client, supplier. That way if there's any indexer available it can be used. While the other solution also works it would require a whole table scan in every case.

Upvotes: 1

Related Questions