Advertisements
Advertisements
Question
Using the table INVENTORY from CARSHOWROOM database, write SQL queries for the following:
- Convert the CarMake to uppercase if its value starts with the letter ‘B’.
- If the length of the car’s model is greater than 4 then fetch the substring starting from position 3 till the end from attribute Model.
Code Writing
Advertisements
Solution
a) Convert the CarMake to uppercase if its value starts with the letter 'B'.
SELECT
CASE
WHEN CarMake LIKE 'B%' THEN UPPER(CarMake)
ELSE CarMake
END AS CarMake
FROM INVENTORY;
b) If the length of the car's Model is greater than 4, fetch the substring starting from position 3 till the end from the Model attribute.
SELECT
CASE
WHEN LENGTH(Model) > 4 THEN SUBSTRING(Model, 3)
ELSE Model
END AS Model
FROM INVENTORY;
shaalaa.com
Is there an error in this question or solution?
