看帮助嘛。FLOOR (T-SQL) Returns the largest integer less than or equal to the given numeric expression.Syntax FLOOR(numeric_expression)Arguments numeric_expression Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type. Return TypesReturns the same type as numeric_expression.
谢谢你,这个函数我明白了,可是它不管符合不符合都给我回滚了。 CREATE TRIGGER [FIRST_SNA_CONS] ON [SNATCH] FOR INSERT, UPDATE AS IF UPDATE(FIRST_SNATCH) DECLARE @FIRST DECIMAL SELECT @FIRST = FIRST_SNATCH FROM INSERTED IF( ( @FIRST / 2.5 ) - FLOOR( @FIRST / 2.5 ) ) <> 0 BEGIN ROLLBACK TRAN END
Returns the largest integer less than or equal to the given numeric expression.Syntax
FLOOR(numeric_expression)Arguments
numeric_expression Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type. Return TypesReturns the same type as numeric_expression.
CREATE TRIGGER [FIRST_SNA_CONS] ON [SNATCH]
FOR INSERT, UPDATE
AS
IF UPDATE(FIRST_SNATCH)
DECLARE @FIRST DECIMAL
SELECT @FIRST = FIRST_SNATCH FROM INSERTED
IF( ( @FIRST / 2.5 ) - FLOOR( @FIRST / 2.5 ) ) <> 0
BEGIN
ROLLBACK TRAN
END
DECLARE @FIRST DECIMAL
DECIMAL相当于DECIMAL(n,0)
也就是说,用你的写法,小数位会被舍掉。结果自然不对了。建议你加上精度。如:
decimal(n,m)
然后再用nononono兄的写法:
IF abs( ( @FIRST / 2.5 ) - FLOOR( @FIRST / 2.5 ) ) < 0.000001
SELECT @FIRST = Floor(FIRST)*10 FROM INSERTED
IF @FIRST%25<>0
BEGIN
ROLLBACK TRANSACTION
END
SELECT @FIRST = Floor(FIRST*10) FROM INSERTED
IF @FIRST%25<>0
BEGIN
ROLLBACK TRANSACTION
END