/*
You are given a table named Sample with the following columns:
ID: A unique identifier for each row.
Letter: A string containing a word where the first letter may be either lowercase or uppercase.
Your task is to write an SQL query to transform the table such that:
1. If the first letter of the word is in lowercase, it should be converted to uppercase.
2. If the first letter of the word is in uppercase, it should be converted to lowercase.
3. The rest of the letters in the word should remain unchanged.
*/
-- create a table
CREATE TABLE sample (
ID INTEGER,
Letter Varchar(15)
);
-- insert values
INSERT INTO sample VALUES (1, 'apple');
INSERT INTO sample VALUES (2, 'Mango');
INSERT INTO sample VALUES (3, 'banana');
INSERT INTO sample VALUES (2, 'orange');
INSERT INTO sample VALUES (2, 'Grapes');
SELECT
ID,
CASE
WHEN BINARY LEFT(Letter,1) = BINARY UPPER(LEFT(Letter,1)) THEN CONCAT(LOWER(LEFT(Letter,1)),'',SUBSTR(Letter,2))
ELSE CONCAT(UPPER(LEFT(Letter,1)),'',SUBSTR(Letter,2))
END as a
FROM sample;
To embed this program on your website, copy the following code and paste it into your website's HTML: