Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Select values starting with a capital letter

Tags:

sql

sql-server

I have a table with a varchar type column. I want to select values from this column which start with a capital letter only.

For example

MyTable

Col1          Col2

Argentina     2
Brasil        3
uruguay       4

I want my select query to return:

Argentina
Brasil
like image 540
Guillermo Zooby Avatar asked Dec 07 '15 13:12

Guillermo Zooby


People also ask

How do I get the first letter of a capital in SQL?

Use the INITCAP() function to convert a string to a new string that capitalizes the first letter of every word. All other letters will be lowercase. This function takes one parameter as a string and changes the capitalization for each word as described.

How do you capitalize the first letter of every word in SQL Server?

We use SQL UPPER function to convert the characters in the expression into uppercase. It converts all characters into capital letters.

How do you capitalize in SQL?

If you want to display a string in uppercase, use the SQL UPPER() function. This function takes only one argument: the string column that you want to convert to uppercase.


1 Answers

This is a bit of a pain. You can use ASCII() or COLLATE, but these depend on how the data is stored. For varchar() and char(), this will work:

where ASCII(left(col1, 1)) between ASCII('A') and ASCII('Z')
like image 167
Gordon Linoff Avatar answered Sep 18 '22 13:09

Gordon Linoff