December 14, 2012 at 3:18 am
Hi guys,
I have an employee table, in this table there is a column called employeeId(Varchar(5000)).
Now i want only to retrieve the result set of char type
Exapmle
EmployeeId
123
ABC
259
CSD
GFRG
EWSF
369
Soluntion:
I want only ABC,CSD,GFRG,EWSF from the above table excluding the numbers
December 14, 2012 at 3:42 am
Like this:
SELECT *
FROM employee
WHERE employeeId LIKE '%[A-Z]%'
AND employeeId NOT LIKE '%[0-9]%'
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
December 14, 2012 at 3:44 am
If employeeID does not contain combination of both alphabets and numerals than you can use this also:
SELECT *
FROM employee
WHERE employeeId LIKE '%[A-Z]%'
In the earlier post, I assumed that employeeId can be a combination of both alphabets and numerals. e.g. ABC123
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
December 14, 2012 at 7:15 am
farooq.hbs (12/14/2012)
Hi guys,I have an employee table, in this table there is a column called employeeId(Varchar(5000)).
Now i want only to retrieve the result set of char type
Exapmle
EmployeeId
123
ABC
259
CSD
GFRG
EWSF
369
Soluntion:
I want only ABC,CSD,GFRG,EWSF from the above table excluding the numbers
I have to ask... why in the world are you folks using a VARCHAR(5000) for an EmployeeID column that probably shouldn't ever be larger that 50 or so characters. It's really not good for indexing and could easily go "out of row" if any given row exceeds about 8,060 bytes in total because of other columns built in such a fashion. Don't forget... that includes ANY table that includes this column as the same datatype.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 14, 2012 at 7:19 am
Lokesh Vij (12/14/2012)
If employeeID does not contain combination of both alphabets and numerals than you can use this also:
SELECT *
FROM employee
WHERE employeeId LIKE '%[A-Z]%'
In the earlier post, I assumed that employeeId can be a combination of both alphabets and numerals. e.g. ABC123
Oh, be careful now. That won't exclude names with numbers in them. You'll need to use some "double NOTs". If you want rows that contain ONLY alphabetic characters, then the following will do the trick.
SELECT *
FROM employee
WHERE employeeId NOT LIKE '%[^A-Z]%'
The circumflex is another "NOT".
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply