Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use wildcard characters in this?

Tags:

sql

sql-server

I have a table of this manner:

+---------+--------------------+ 
|ID       | Component          |
+---------+--------------------+
|00241147 | 000000001000245598 |  
|00241147 | 000000001000090069 | 
|00249207 | 000000002510256707 | 
|00249208 | 000000002510245146 | 
+---------+--------------------+

I want to select only those rows where Component is starting with '1'.

I'm using the following code:

select * from Table where Component like '%1%'
like image 931
inadvisableguy Avatar asked Dec 10 '25 16:12

inadvisableguy


1 Answers

Cast them as bigint and read 1 using left() function

select * from Table where left(cast(Component as bigint), 1) = 1

Note : This above assumes that Component column has varchar datatype

EDIT : Thanks for making demo for clarification by Uwe Keim

http://sqlfiddle.com/#!6/1987d/4

like image 192
Yogesh Sharma Avatar answered Dec 13 '25 09:12

Yogesh Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!