Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:18:46+00:00 2026-06-12T09:18:46+00:00

I am using Sql Server 2008 Say you have a table named Weights and

  • 0

I am using Sql Server 2008

Say you have a table named “Weights” and within that table you have a column named “Weight” with its data type defined as “real” with the following data.

Weight(real data type)

2
2.001
2.002
2.003
2.004
2.005
2.006
2.007
2.008
2.009
3

Here is the query I am running in the new query window against the table

declare @sql nvarchar(MAX)
declare @params nvarchar(MAX)
declare @interval float = .001
declare @conversion float = 1/@interval         

set @sql =
N'select FLOOR(Weight * @INPUTconversion)*@INPUTinterval as [Weight],
COUNT(1) as ''Count''
FROM dbo.Weights
GROUP BY FLOOR(Weight*@INPUTconversion)*@INPUTinterval
order by FLOOR(Weight*@INPUTconversion)*@INPUTinterval'

set @params =
N'
@INPUTconversion real,
@INPUTinterval float'

exec sp_executesql @sql, @params,  
@INPUTconversion = @conversion,
@INPUTinterval = @interval

Here is the result which appears to be wrong.

Weight Count

2 2
2.002 1
2.003 1
2.004 1
2.005 1
2.006 1
2.007 2
2.009 1
3 1

How can I make the return look like this using the same query? Do I need to change my variable data types?

Weight Count

2 1
2.001 1
2.002 1
2.003 1
2.004 1
2.005 1
2.006 1
2.007 1
2.008 1
2.009 1
3 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:18:46+00:00Added an answer on June 12, 2026 at 9:18 am

    This is clearly a problem of numeric representation in the data. What you are seeing as 2.001 must really be stored as 2.00099999999999 . . . for some number of “9”s.

    I think your best solution is to change the data type to something like DECIMAL(12, 6), where what you see is what you get.

    Alternatively, you could do some fuzzy math, by adding a very small increment to the value:

    select FLOOR(Weight * @INPUTconversion + 0.0000001)*@INPUTinterval as [Weight]
    

    This will treat a weight really close to 2.001 as 2.001 rather than just a smidgen less.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using T-Sql with SQL Server 2008. Say I have parent table: Projects: ProjectID
I'm using SQL Server 2008. Let's say I have two hypothetical tables like below:
I'm using SQL Server 2008. I have a table with x amount of rows.
Ok I'm using SQL Server 2008 and have a table field of type VARCHAR(MAX)
Using SQL Server 2008. I have multiple Locations which each contain multiple Departments which
Using SQL Server 2008, is there a way to allow inserts to a table
I am using SQL Server 2008 R2, I have a script to update the
Hi i am using SQL Server 2008 R2, i have lots of procedures in
Here is one very interesting problem. I am using SQL Server 2008. I have
(Using SQL Server 2008) I need some help visualizing a solution. Let's say I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.