Using Round in a sql query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cryptotech2000
    New Member
    • Jun 2007
    • 12

    Using Round in a sql query

    I have the following two cases in my sql query I would like to round the results (round 0) however I cannot figure out the correct syntax to use round in this instance.. any help on this would be greatly appreciated

    Code:
    CASE WHEN tbl_CCMonitorSheetAnswer.Answer = 'False' THEN (tbl_CCMonitorFormQuestion.Points - tbl_CCMonitorFormQuestion.Points) 
                          WHEN tbl_CCMonitorSheetAnswer.Answer IS NULL THEN NULL ELSE tbl_CCMonitorFormQuestion.Points END AS [Achieved Points], 
    
                          CASE WHEN tbl_CCMonitorSheetAnswer.Answer IS NULL THEN NULL ELSE tbl_CCMonitorFormQuestion.Points END AS [Max Points],
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Round(0) ?

    Do you want to remove the decimal place?

    Here's the full ROUND syntax.

    -- CK

    Comment

    • cryptotech2000
      New Member
      • Jun 2007
      • 12

      #3
      Yes that is correct (I want to remove the decimal place).. and i have read over that but I cannot figure out how to use round in conjunction with the case syntax (my example above) how would i incorporate round into that select?

      Comment

      • cryptotech2000
        New Member
        • Jun 2007
        • 12

        #4
        I can do it on the reporting end and use Round(Fields!Ac hieved_Points.V alue) but it then rounds all Null Values to 0 and null values need to remain Null

        Comment

        • cryptotech2000
          New Member
          • Jun 2007
          • 12

          #5
          Also if i modify my query like the following.. it only rounds to the nearest whole number but leaves the decimal place

          Code:
          CASE WHEN tbl_CCMonitorSheetAnswer.Answer = 'False' THEN Round(tbl_CCMonitorFormQuestion.Points - tbl_CCMonitorFormQuestion.Points, 0) 
          WHEN tbl_CCMonitorSheetAnswer.Answer IS NULL THEN NULL ELSE Round(tbl_CCMonitorFormQuestion.Points, 0) END AS [Achieved Points], 
          CASE WHEN tbl_CCMonitorSheetAnswer.Answer IS NULL THEN NULL ELSE round(tbl_CCMonitorFormQuestion.Points, 0) END AS [Max Points],

          Comment

          • ck9663
            Recognized Expert Specialist
            • Jun 2007
            • 2878

            #6
            Originally posted by cryptotech2000
            I can do it on the reporting end and use Round(Fields!Ac hieved_Points.V alue) but it then rounds all Null Values to 0 and null values need to remain Null
            Then a CASE function would do

            Code:
            Value = case when Fields!Achieved_Points.Value is null then null else Round(Fields!Achieved_Points.Value) end
            -- CK

            Comment

            Working...