Yeah I trited your query it is giving some error like "Incorrect syntax near the keyword 'as'" and Must declare the scalar variable "@SelectedValue".
I think you have mentioned @SelectedValue as varchar but in my db it is float that is why it is giving error. And that too
another post solved my issue. Thanks for support. Thank you.
Hi again,
No error is coming due to "DEACLARE" , which is wrong, use DECLARE instead of it. (In hurry, I wrote wrong spell)
You can create store procedure in order to return what you need in any of case.
CREATE PROCEDURE GetSize
@SelectedValue DECIMAL
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM Table1
WHERE Size1 >= @SelectedValue ANd Size2 <= @SelectedValue
END
Hope it will resolve your query as you mention earlier.
nag4dotnet
Member
664 Points
173 Posts
Select query between two sizes
Jan 28, 2013 04:43 AM|LINK
Hi I Have a database table like this
And I have a dropdown list with values like this
0.5
0.75
1
1.5
2
2.5
3
4
5
10
12
14
16
18
20
24
"If I Select 0.75 as selected value. I want to get the first record description because it lies between size 0.5 and 1.5. "
How can i achieve this. Please give me some idea about data base query.
Regards
----------
Nag
umairaslam22
Contributor
3992 Points
846 Posts
Re: Select query between two sizes
Jan 28, 2013 04:49 AM|LINK
Write your query like this
Select * form your_tableName Where
Size1 >= .75 And Size2 <= .75
MCP
Blog
Please remember to Mark as answer if any post help you , it help others to find right solution in less time
matifnadeem
Contributor
4972 Points
1158 Posts
Re: Select query between two sizes
Jan 28, 2013 04:51 AM|LINK
Hi,
Try this
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
urenjoy
Star
13533 Points
2036 Posts
Re: Select query between two sizes
Jan 28, 2013 04:52 AM|LINK
select * from mytable
where @selectedSize between Size1 and Size2
nag4dotnet
Member
664 Points
173 Posts
Re: Select query between two sizes
Jan 28, 2013 05:08 AM|LINK
Thanks to all for quick response and solution.
The given querys is working fine for '0.75' but when I execute the same query for 2.5 it is resulting all the records.
Regards
----------
Nag
matifnadeem
Contributor
4972 Points
1158 Posts
Re: Select query between two sizes
Jan 28, 2013 05:23 AM|LINK
Hi nag4dotnet again,
Have you tried mine code mention in previous post? It will solve your issue.
Let me know if any query still remains
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
nag4dotnet
Member
664 Points
173 Posts
Re: Select query between two sizes
Jan 28, 2013 05:31 AM|LINK
Yeah I trited your query it is giving some error like "Incorrect syntax near the keyword 'as'" and Must declare the scalar variable "@SelectedValue".
I think you have mentioned @SelectedValue as varchar but in my db it is float that is why it is giving error. And that too
another post solved my issue. Thanks for support. Thank you.
Regards
----------
Nag
matifnadeem
Contributor
4972 Points
1158 Posts
Re: Select query between two sizes
Jan 28, 2013 06:12 AM|LINK
Hi again,
No error is coming due to "DEACLARE" , which is wrong, use DECLARE instead of it. (In hurry, I wrote wrong spell)
You can create store procedure in order to return what you need in any of case.
Hope it will resolve your query as you mention earlier.
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn