question

jhonny_86 avatar image
jhonny_86 asked

Get values between 00 and 16

Hi! I'm stuck with this sql filtering... I have a column that is a varchar with values like: 000112-1234 020112-1233 040112-1231 050112-1534 090112-1634 160112-1734 170112-1734 181112-1224 190112-1214 What I want to do is to only retrieve the rows between 00 and 16. In this example I don't want to see the last 3 rows since they start with 17,18 and 19. What I started to do is CAST(LEFT(ISNUMERIC(t.NumberField),2) as int) between 00 and 16 which doesn't work. Very appreciated
sqlfilter
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
I think this will work. WHERE case when ISNUMERIC(LEFT(t.NumberField,2))=1 then CAST(LEFT(t.NumberField,2) as smallint) else -1 end BETWEEN 0 AND 16
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.