Float

  • Hi,

    I am having problem with generating a Float which generates a output of adding 1 every second month.

    Currently, I have a solution of dividing the target by 365, but then I wont get the value to change exactly when the month starts.

    My data consists of date, employee id and target

    Hope one of you, can help!

    BR

     

  • Can you elaborate it a bit more? What is meant with "generates a output of adding 1 every second month"

    0 = beginning of month?

    1= end of month

    float, secondes passed since beginning of month? 0,....?

  • Hi,

    Sorry for the vague explanation 🙂

    - It is meant by, as each employee have a target of 6 for the year. Thereby should they, have a value/target of 1, after the first two months, and a value/target of 2, after four months and so on.

    The value/target should increase on the first day of the new month,

    Hope this makes sense 😅

  • Why on earth would you use data type FLOAT ????  ( especially if smallint / tinyint ) would do !

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Hi Johan,

    Good question, too be perfectly honest, have I not dealt that much in Sql beforehand. The reason why I wrote float in the first place, was that my predecessor, used that one. But it is great if the other ones are a better fit

    - You learn something new every day  😊

  • The best way to think of FLOAT is it will give you approximately the right answer. It is great when that is the result you need, but not so good when accuracy is important.

    Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.

    When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara

  • Hmm, okay I will take that into consideration in the future, thank you! 🙂

    - Do you know how I can use the ones you mentioned, to generate an output / increase the value from the first day of each month?

  • Can you simply divide the month number of the date by two? Dividing an integer by an integer causes rounding, so if the month is 5, the result is 2, not 2.5.

    DECLARE @IndexDate DATE = '2022-01-23'
    SELECT @IndexDate AS TheDate, DATEPART(MONTH, @IndexDate)/2 AS 'Target'

    SET @IndexDate = '2022-02-01'
    SELECT @IndexDate AS TheDate, DATEPART(MONTH, @IndexDate)/2 AS 'Target'

    SET @IndexDate = '2022-05-01'
    SELECT @IndexDate AS TheDate, DATEPART(MONTH, @IndexDate)/2 AS 'Target'

     

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply