English

Using the table INVENTORY from CARSHOWROOM database, write SQL queries for the following: a) Convert the CarMake to uppercase if its value starts with the letter ‘B’.

Advertisements
Advertisements

Question

Using the table INVENTORY from CARSHOWROOM database, write SQL queries for the following:

  1. Convert the CarMake to uppercase if its value starts with the letter ‘B’.
  2. 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?
Chapter 1: Querying and SQL Functions - Intext Questions [Page 9]

APPEARS IN

NCERT Informatics Practices [English] Class 12
Chapter 1 Querying and SQL Functions
Intext Questions | Q 2. | Page 9
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×