Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

sql

How to use the INICAP() function in SQL

Maria Elijah

The SQL INITCAP() function

The INITCAP() function converts the first character of each string to upper case and the remaining characters to lower case.

Syntax

INITCAP(string)

Parameter

  • string: This represents the string to be altered.

Example

The following code shows how to use the INITCAP() function in SQL:

CREATE TABLE Product (
    id int,
    product_name varchar(50),
    price varchar(50),
    product_id varchar (20)
);

-- Insert data
INSERT INTO Product
VALUES (101,'t-shirt','$100','boo-01-345');
INSERT INTO Product
VALUES (102,'hand Bag','$65','boo-01-238');
INSERT INTO Product
VALUES (103,'ipad','$1200','boo-01-103');
INSERT INTO Product
VALUES (104,'cereal','$30','boo-01-775');
INSERT INTO Product
VALUES (105,'microwave','$520','boo-01-788');
INSERT INTO Product
VALUES (106,'cloth clips','$15','boo-01-924');
INSERT INTO Product
VALUES (108,'zara Perfume','$120','boo-01-245');

-- Query 
SELECT id, product_name, INITCAP(product_name) AS new_product_name
FROM Product;
Implementation of the INITCAP() function

Explanation

  • Lines 1–6: We create a table called Product that has the id, product_name, price, and book_id columns.
  • Lines 9–22: We insert data into the table.
  • Lines 25–26: We retrieve the data in the id, and product_name columns. We then use the INITCAP() function to alter the first character of each product name to uppercase and store it in a new column, new_product_name.

RELATED TAGS

sql
RELATED COURSES

View all Courses

Keep Exploring