SQL Server/T-SQL/String Functions/STR

Материал из SQL эксперт
Версия от 13:19, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Specifying an overall length greater than the length of the value, decimal point, and the decimal value, the result will be left-padded with spaces

   <source lang="sql">

1> 2> --Specifying an overall length greater than the length of the value, decimal point, 3> --and the decimal value, the result will be left-padded with spaces 4> 5> SELECT STR(1, 12, 4) 6> GO


     1.0000

(1 rows affected) 1> 2>

      </source>
   
  


STR(100.325,7)

   <source lang="sql">

1> --the following will return 100 (note the 4 spaces): 2> 3> SELECT STR(100.325,7) 4> GO


   100

(1 rows affected) 1>

      </source>
   
  


STR(123. 4)

   <source lang="sql">

1> SELECT STR(123.456789, 8, 4) 2> GO


123.4568 (1 rows affected) 1> 2>

      </source>
   
  


STR() Function: converts a numeric value to a string

   <source lang="sql">

1> 2> -- STR() Function: converts a numeric value to a string. 3> 4> SELECT STR(123.4, 8, 4) 5> GO


123.4000 (1 rows affected) 1>

      </source>
   
  


STR() function right-fills the decimal value with zeros

   <source lang="sql">

1> 2> -- STR() function right-fills the decimal value with zeros 3> SELECT STR(1, 6, 4) 4> GO


1.0000 (1 rows affected) 1> 2>

      </source>
   
  


STR: takes a numeric value and changes the data type to a char

   <source lang="sql">

1> -- STR: takes a numeric value and changes the data type to a char. 2> 3> --STR(number_to_convert, length_of_string, [number_of_decimal_places]) 4> 5> SELECT STR(100.325,7,2) 6> GO


100.33

(1 rows affected) 1>

      </source>