0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQLServerで0方向への切り捨てを行う方法

Last updated at Posted at 2020-07-29

説明

ROUND ( numeric_expression , length [ ,function ] )
にて、function に1を指定すると0方向への丸めが行われます。

検証結果

numeric_expression length function Resulet
1.5 0 2.0
0.5 0 1.0
-0.5 0 -1.0
-1.5 0 -2.0
1.5 0 0 2.0
0.5 0 0 1.0
-0.5 0 0 -1.0
-1.5 0 0 -2.0
1.5 0 1 1.0
0.5 0 1 0.0
-0.5 0 1 0.0
-1.5 0 1 -1.0

検証方法

検証結果のResultを除いたテーブルを作成し、
case when Table_1.[function] is null then ROUND(Table_1.expression, Table_1.length) when Table_1.[function] is not null then ROUND(Table_1.expression, Table_1.length, Table_1.[function]) END
を実行。

補足(FLOORを使用した場合)

numeric_expression Resulet
1.5 1
0.5 0
-0.5 -1
-1.5 -2

参考URL

(https://docs.microsoft.com/ja-jp/sql/t-sql/functions/round-transact-sql?view=sql-server-ver15)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?