1

I am trying to pull data from a table with the filter weight < 25 kgs , but my table has weight in pounds, I tried using below sql can some one please tell me is this the right way to do it or is there any other way .

 select * from dbo.abc
     where (round((WEIGHT * 0.453592 ),0) < 25)
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • 1
    There are other ways, but the one you have there looks like it could work ok. Are you having a specific problem? – Stephen Turner Mar 30 '15 at 21:01
  • 5
    Why not just convert the 25kg into lbs (e.g. 55.1156) and use that in the query? – adrianbanks Mar 30 '15 at 21:01
  • This should work, but if you are doing it often, perhaps you should create a [scalar user-defined function](https://msdn.microsoft.com/en-us/magazine/cc164062.aspx). – Turophile Mar 30 '15 at 21:02
  • webturner , This first time i am writing this logic, so want to make sure i am writing this query right –  Mar 30 '15 at 21:21

2 Answers2

3

Your solution would work, but it's not sargaeble. A better solution would be to convert your 25kgs to lbs. That way, if you have an index on your WEIGHT column, the query analyzer could make use of it.

One additional note: Why round to 0 decimal places? You'll lose accuracy that way. Unless you have some requirement to do so, I'd drop the rounding. It's unnecessary overhead.

Community
  • 1
  • 1
DeadZone
  • 1,633
  • 1
  • 17
  • 32
0

As other people mentioned, you don't want to convert weight as it will cause SQL Server not to use your index. So try this instead:

SELECT *
FROM dbo.acb
WHERE WEIGHT < ROUND(25/.453592,4)
Stephan
  • 5,891
  • 1
  • 16
  • 24