Condividi tramite


CARTELLO (Transact-SQL)

Si applica a:SQL ServerDatabase SQL di AzureIstanza gestita di SQL di AzureAzure Synapse AnalyticsPiattaforma di analisi (PDW)Endpoint di analisi SQL in Microsoft FabricMagazzino in Microsoft FabricDatabase SQL in Microsoft Fabric

Restituisce il segno positivo (+1), zero (0) o il segno negativo (-1) dell'espressione specificata.

Convenzioni relative alla sintassi Transact-SQL

Sintassi

SIGN ( numeric_expression )  

Argomenti

numeric_expression
Espressione della categoria di tipi di dati numerici esatti o numerici approssimativi, ad eccezione del tipo di dati bit.

Tipi restituiti

Espressione specificata Tipo restituito
bigint bigint
int/smallint/tinyint int
money/smallmoney money
numeric/decimal numeric/decimal
Altri tipi float

Esempi

Nell'esempio seguente vengono restituiti i valori SIGN dei numeri compresi tra -1 e 1.

DECLARE @value REAL  
SET @value = -1  
WHILE @value < 2  
   BEGIN  
      SELECT SIGN(@value)  
      SET NOCOUNT ON  
      SELECT @value = @value + 1  
      SET NOCOUNT OFF  
   END  
SET NOCOUNT OFF  
GO  

Il set di risultati è il seguente.

(1 row(s) affected)  
  
------------------------   
-1.0                       
  
(1 row(s) affected)  
  
------------------------   
0.0                        
  
(1 row(s) affected)  
  
------------------------   
1.0                        
  
(1 row(s) affected)  

Esempi: Azure Synapse Analytics e Piattaforma di strumenti analitici (PDW)

Nell'esempio seguente vengono restituiti i valori SIGN di tre numeri.

SELECT SIGN(-125), SIGN(0), SIGN(564);  

Il set di risultati è il seguente.

-----  -----  -----  
-1     0      1

Vedi anche

Funzioni matematiche (Transact-SQL)