PDA

View Full Version : sql variable definieren bzw. runden



rr2001
13-11-07, 15:48
hallo Leute,
wie kann ich variable "var_x" so definieren bzw. runden,
dass im sql-Ergebnis nur max. 2 Dezimalstellen angezeigt werden:

select datei_1.var_1, datei_1.var_2,
var_1/var_2 as var_x
from...

Vielen Dank

woki
14-11-07, 08:22
>>-ROUND--(--expression-1--,--expression-2--)------------------><

expression–1
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. A string argument is converted to double-precision floating point before evaluating the function. For more information on converting strings to double-precision floating point, see DOUBLE_PRECISION or DOUBLE.
expression–2
The argument must be an expression that returns a value of a built-in BIGINT, INTEGER, or SMALLINT data type.

If expression–2 is positive, expression–1 is rounded to the expression–2 number of places to the right of the decimal point.

If expression–2 is negative, expression–1 is rounded to 1 + (the absolute value of expression–2) number of places to the left of the decimal point. If the absolute value of expression–2 is greater than the number of digits to the left of the decimal point, the result is 0. (For example, ROUND(748.58,-4) returns 0.)
Quelle: SQL Reference (http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/db2/rbafzmstscale.htm)

In deinem Fall:

select datei_1.var_1, datei_1.var_2,
ROUND(var_1/var_2, 2) as var_x
from...

rr2001
14-11-07, 08:52
klappt vorzüglich.

Vielen Dank