Monday, October 1, 2007

SQL-Changing The Case

I'm going to site today. And have a problem with user database that the user want me to change the data. They have 2055 data. That's a lot of number. At first I have decided that want to make a simple program that could change all the case. After a few minutes I found one script that would make my job more easier.

Changing Strings to Lower Case

The Transact SQL Lower function is used to convert strings to all lower case. For example, the following statement returns a lower case ProductName from the Products table of the Northwind sample database:

SELECT LOWER(ProductName) as ProductName FROM Products

Changing Strings to Upper Case

The Transact SQL Upper function is used to convert strings to all upper case (i.e. capitals). For example, the following statement returns an upper case ProductName from the Products table of the Northwind sample database:

SELECT UPPER(ProductName) as ProductName FROM Products

Changing the Case of Database Table Columns

If you need to permanently change the case of text within specific database columns, then a SQL statement like the following can be used:

UPDATE Products SET ProductName = UPPER(ProductName)

A WHERE clause could also be used if only certain rows needed to be changed.