April 7, 2010 at 9:14 am
Hi,
How to find the first letter is a character or number in a column?
My column has s12345, 345678, n789054
Thank you,
VG
April 7, 2010 at 9:32 am
test for numeric:
ISNUMERIC(LEFT(yourFieldName,1)) = 1
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgApril 7, 2010 at 9:49 am
Sorry, I would have explained little more about my situation.
I want to read the column value along with some other select statements.
select column1, column2,
case column3
when countrycode = 'US' then select the value from the column which starts with a character like 's12345'
else
column3
Thanks again..
VG
April 7, 2010 at 10:21 am
You know, the people that help out here are all un-paid volunteers. Providing the DDL scripts (CREATE TABLE, CREATE INDEX, etc.) for the tables affected, and INSERT statements to put some test data into those tables that shows your problem will go a long way in getting people to look at your issue and help you out. Please include code for what you have already tried. Don't forget to include what your expected results should be, based on the sample data provided. As a bonus to you, you will get tested code back. For more details on how to get all of this into your post, please look at the first link in my signature.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 7, 2010 at 11:06 am
This should be what you're looking for. If not we'll need some more information like Wayne said. There's a link in his signature on getting better assistance that explains the best way to post test data.
select column1, column2,
case
when countrycode = 'US' then ISNUMERIC(LEFT(column3,1))
else column3
end 'columnalias'
from tablename
April 7, 2010 at 7:25 pm
Jason Selburg (4/7/2010)
test for numeric:ISNUMERIC(LEFT(yourFieldName,1)) = 1
Heh... you sure about that ol' friend?
SELECT ISNUMERIC(LEFT('$Howdy',1)),
ISNUMERIC(LEFT(',Howdy',1)),
ISNUMERIC(LEFT('.Howdy',1)),
ISNUMERIC(LEFT('+Howdy',1)),
ISNUMERIC(LEFT('-Howdy',1)),
ISNUMERIC(LEFT(CHAR(9)+'Howdy',1))
Lutz has the correct idea. Never use ISNUMERIC as an ISALLDIGITS function because that's not what it is.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 8, 2010 at 6:26 am
Jeff Moden (4/7/2010)
Jason Selburg (4/7/2010)
test for numeric:ISNUMERIC(LEFT(yourFieldName,1)) = 1
Heh... you sure about that ol' friend?
SELECT ISNUMERIC(LEFT('$Howdy',1)),
ISNUMERIC(LEFT(',Howdy',1)),
ISNUMERIC(LEFT('.Howdy',1)),
ISNUMERIC(LEFT('+Howdy',1)),
ISNUMERIC(LEFT('-Howdy',1)),
ISNUMERIC(LEFT(CHAR(9)+'Howdy',1))
Lutz has the correct idea. Never use ISNUMERIC as an ISALLDIGITS function because that's not what it is.
😛
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgApril 8, 2010 at 8:10 am
Try this one...
declare @n varchar(10)
set @n ='10'
select case when ascii(left(@n,1)) > 47 and ascii(left(@n,1)) < 58 then 1 else 0 end
karthik
April 8, 2010 at 8:20 am
Is this too simple??
Where Col LIKE '[0-9]%'
That's my favorite for clarity...
April 9, 2010 at 9:55 am
More than one way to skin this cat correctly, and probably more than one way to do it INcorrectly as well! 🙂
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply