w3resource

AdventureWorks Database: Join the name, color etc.

SQL Query - AdventureWorks: Exercise-60 with Solution

60. From the following table write a query in SQL to concatenate the name, color, and productnumber columns.

Sample table: production.product


Click to view Full table

Sample Solution:

SELECT CONCAT( name, '   color:-',color,' Product Number:', productnumber ) AS result, color
FROM production.product;

Sample Output:

result                                                         |color |
---------------------------------------------------------------+------+
Adjustable Race   color:- Product Number:AR-5381               |      |
Bearing Ball   color:- Product Number:BA-8327                  |      |
BB Ball Bearing   color:- Product Number:BE-2349               |      |
Headset Ball Bearings   color:- Product Number:BE-2908         |      |
Blade   color:- Product Number:BL-2036                         |      |
LL Crankarm   color:-Black Product Number:CA-5965              |Black |
ML Crankarm   color:-Black Product Number:CA-6738              |Black |
HL Crankarm   color:-Black Product Number:CA-7457              |Black |
Chainring Bolts   color:-Silver Product Number:CB-2903         |Silver|
Chainring Nut   color:-Silver Product Number:CN-6137           |Silver|
Chainring   color:-Black Product Number:CR-7833                |Black |
...

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Find the position of the string 'yellow'.
Next: Concatenate the columns separated by a unique character.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

Ref : https://bit.ly/3VKT5M8