Skip to main content
added 238 characters in body
Source Link
McNets
  • 23.9k
  • 11
  • 50
  • 89

Due 'qtyordered' is an integer, you need to either, CAST/CONVERT it to decimal, or use a decimal/float value. (3.0)

Select
partid, qtyordered
,CEILING(qtyordered/3.0) As [First] --want to be 2
,CEILING(qtyordered/3.0) As [Second] --want to be 2
,FLOOR(qtyordered/3) As [Third] --want to be 1
FROM Orders
WHERE partid = 'RR200'
GO
partid | qtyordered | First | Second | Third
:----- | ---------: | :---- | :----- | ----:
RR200  |          5 | 2     | 2      |     1

dbfiddle here

According to MS DOCS, CEILING returns same type as the numeric expresion:

Return Types
Returns the same type as numeric_expression

Due 'qtyordered' is an integer, you need to either, CAST/CONVERT it to decimal, or use a decimal/float value. (3.0)

Select
partid, qtyordered
,CEILING(qtyordered/3.0) As [First] --want to be 2
,CEILING(qtyordered/3.0) As [Second] --want to be 2
,FLOOR(qtyordered/3) As [Third] --want to be 1
FROM Orders
WHERE partid = 'RR200'
GO
partid | qtyordered | First | Second | Third
:----- | ---------: | :---- | :----- | ----:
RR200  |          5 | 2     | 2      |     1

dbfiddle here

Due 'qtyordered' is an integer, you need to either, CAST/CONVERT it to decimal, or use a decimal/float value. (3.0)

Select
partid, qtyordered
,CEILING(qtyordered/3.0) As [First] --want to be 2
,CEILING(qtyordered/3.0) As [Second] --want to be 2
,FLOOR(qtyordered/3) As [Third] --want to be 1
FROM Orders
WHERE partid = 'RR200'
GO
partid | qtyordered | First | Second | Third
:----- | ---------: | :---- | :----- | ----:
RR200  |          5 | 2     | 2      |     1

dbfiddle here

According to MS DOCS, CEILING returns same type as the numeric expresion:

Return Types
Returns the same type as numeric_expression

Source Link
McNets
  • 23.9k
  • 11
  • 50
  • 89

Due 'qtyordered' is an integer, you need to either, CAST/CONVERT it to decimal, or use a decimal/float value. (3.0)

Select
partid, qtyordered
,CEILING(qtyordered/3.0) As [First] --want to be 2
,CEILING(qtyordered/3.0) As [Second] --want to be 2
,FLOOR(qtyordered/3) As [Third] --want to be 1
FROM Orders
WHERE partid = 'RR200'
GO
partid | qtyordered | First | Second | Third
:----- | ---------: | :---- | :----- | ----:
RR200  |          5 | 2     | 2      |     1

dbfiddle here