tmajor99
asked on
SQL Select - How to checks a column that contains numerics in first 3 positions
I need to SQL Select that can check if column has numerics in the first 3 positions.
My Table: AltCode
Test1
123Blah
4Peak
Hery*1
In the example about, I need a SQL Select Query that would identify rows:
123Blah
4Peak
My Table: AltCode
Test1
123Blah
4Peak
Hery*1
In the example about, I need a SQL Select Query that would identify rows:
123Blah
4Peak
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I need to SQL Select that can check if column has numerics in the first 3 positions.
This clearly means you have to check numeric values in the first 3 positions.
Hi Tmajor,
Please refer my tested solution which perfectly cater to your above problem.
Regards,
Pawan
And this clearly shows that the author also wants anything that starts with a number:
"In the example about, I need a SQL Select Query that would identify rows:
123Blah
4Peak"
So, by the logic what he needs is anything starting with a number no matter is if only the first or the first three.
"In the example about, I need a SQL Select Query that would identify rows:
123Blah
4Peak"
So, by the logic what he needs is anything starting with a number no matter is if only the first or the first three.
The author has clearly written - I need to SQL Select that can check if column has numerics in the first 3 positions..
To see if any of the first three chars contain a numeric digit (0 thru 9):
SELECT ...
FROM MyTable
WHERE PATINDEX('%[0-9]%', AltCode) BETWEEN 1 AND 3
SELECT ...
FROM MyTable
WHERE PATINDEX('%[0-9]%', AltCode) BETWEEN 1 AND 3
@Tmajor,
Your question says something and the answer you selected says something else. The answer you selected will not work if the value is A12YU
Only my solution and Scott's answer will work in any case.
Your question says something and the answer you selected says something else. The answer you selected will not work if the value is A12YU
Only my solution and Scott's answer will work in any case.
Just created a full tested solution for you-
Open in new window
OUTPUT
Open in new window
Hope it helps!