3

I have some different scenario. Roomname column of varchar datatype. I want to get records on the bases of room range: Like: If I am entering A To Z Range of records then I need to get records between roomname A,B,C...Z

If I will Enter Room range R1 to R30 Will get all records between R1 to R30

How can I do this

Vishvadeep singh
  • 1,624
  • 1
  • 19
  • 31

1 Answers1

1

See this answer:

Like Operator in Entity Framework?

You should be able to use that method to narrow down your record results to at least the letter component of your room range. From there a little VB will get you the rest of the way.

'I assume:
'results() is a string array of room numbers formatted like "R1" or "R30"
'rangeStart and rangeEnd are corresponding integers, e.g. 1 and 30

For Each roomName As String In results
    Dim roomNum As Integer = CInt(Mid(roomName, 2))
        If roomNum > rangeStart And roomNum < rangeEnd Then
            'Your code here
        End If
Next room
Community
  • 1
  • 1
Josh
  • 1,088
  • 1
  • 7
  • 16
  • How your integer parameters will works in entityframework? And If I Want to display result A to P How like operator will work here could you please explain? – Vishvadeep singh Jun 23 '15 at 11:35
  • The above code does not involve passing any integer parameters to/from entity framework; only strings. For a range with the Like Operator, use [A-P]*. (The PatIndex documentation doesn't define acceptable patterns, so I assume it uses the same format as Like, but am unable to test at this time.) So something `Dim Pattern As String = "[" & Left(roomStart, 1) & "-" & Left(roomEnd, 1)`, where roomStart and roomEnd are strings like "A1" and "P30". Allowing a range of letters also means a more sophisticated If test to make sure the room is in range for searches such as A30-B1. – Josh Jun 23 '15 at 12:10
  • I hope this helps. It's hard to clarify further without knowing your code and table structure. – Josh Jun 23 '15 at 12:11