• Post Categories

  • Browse Blogs

  • Blog Stats

    • 634,090 hits
  • Syndications

    SQLServerPedia Contributor

T-SQL UPPER(): Change an all lowercase string to uppercase

The T-SQL UPPER() command allows you to change a lowercase string to an uppercase string.

For example, it will allow you to change the word hello to HELLO.

Example 1:

Declare @MyVar varchar(50);
Set @Myvar=’hello’;
Select UPPER(@MyVar)   => Output will be HELLO in uppercase.

You can use the T-SQL UPPER() command with other commands to Capitalize only the first letter of a word.

For example, change florida to Florida.

Example2:

DECLARE @MyVar varchar(50);
SET @Myvar=’florida’;
SELECT UPPER(LEFT(@MyVar,1)) +SUBSTRING(@MyVar,2,49)

Since my string is of length 50, notice that I am selecting the first letter and converting it to upper case and concatenating with the rest 49 letters that are already in lowercase starting with the second position in the string.

T-SQL LOWER(): Change an all uppercase string to lower case

The T-SQL LOWER() command allows you to change an uppercase string to a lowercase string.

For example, it will allow you to change the word HELLO to hello.

Example 1:

Declare @MyVar varchar(50);
Set @Myvar=’HELLO’;
Select LOWER(@MyVar)   => Output will be hello in lowercase.

You can use the T-SQL LOWER() command with other commands to Capitalize only the first letter of a word.

For example, change FLORIDA  to Florida.

Example2:

DECLARE @MyVar varchar(50);
SET @Myvar=’FLORIDA’;
SELECT LEFT(@MyVar,1) +SUBSTRING(LOWER(@MyVar),2,49)

Since my string is of length 50, notice that I am selecting the first letter that is already in uppercase and concatenating with the rest 49 letters in lowercase starting with the second position in the string.

Word Macro to load a Data Warehouse

Recently I came across a very specific requirement for a Data Warehouse project for one of our customers. Due to their very tight data access and transfer security, network packets were not only being encrypted, but they were also being scanned for DML T-SQL statements like Insert, Update and Select. If any of these statements came across the network the packets were immediately dropped.

With a little creativity and help from one of their developers, who by the way is a Microsoft Office MVP, we developed a Word Macro that enabled us to copy/paste data into the data warehouse.

We inserted more than a million rows less than 1 hour, which is not bad given the constraints and maintenance window.

Here is the link to download the script in text format which will work with the Adventure Works sample databases: MacroScript.txt