Click here to Skip to main content
15,886,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have table data like this:

sno             component           subcomponent               Irnumber
1                   1                 c1 to c100                 001
2                   1                 c200 to c444               002
3                   1                 c450,c451,c455             003


here in the text box user enters c50....i need to retrieve first record
1              1              c1 to c100            001


please help me.
Posted
Updated 3-May-15 23:51pm
v3

1 solution

Don't store it like that.
SQL is not good at string manipulations, and you need to find two numbers, extract them, validate them, convert them to an integer, and then compare them.
Instead, change your database to use two integer columns (and possibly an NVARCHAR column for the prefix) and use BETWEEN:
sno component prefix subcomponentStart subcomponentEnd Irnumber
1           1      C                 1             100      001

SQL
SELECT * FROM MyTable WHERE Prefix='C' AND ValueFromUser BETWEEN subcomponentStart AND subcomponentEnd
 
Share this answer
 
Comments
Maciej Los 4-May-15 5:38am    
5ed!
vemsoft 4-May-15 5:58am    
here i want query to find c50 between c1 to c100................
thanks for your suggestion
OriginalGriff 4-May-15 6:14am    
So feed it 50 as the ValueFromUser...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900