STR(float_expression, character_length, number_of_decimal_places) : STR « String Functions « SQL Server / T-SQL Tutorial






5> CREATE TABLE discounts(
6>    discounttype   varchar(40)       NOT NULL,
7>    stor_id        char(4) NULL              ,
8>    lowqty         smallint              NULL,
9>    highqty        smallint              NULL,
10>    discount       dec(4,2)          NOT NULL
11> )
12> GO
1>
2> insert discounts values('Initial Customer',  NULL,   NULL, NULL, 10.5)
3> insert discounts values('Volume Discount',   NULL,   100,  1000, 6.7)
4> insert discounts values('Customer Discount', '8042', NULL, NULL, 5.0)
5> GO

(1 rows affected)

(1 rows affected)

(1 rows affected)
1>
2>
3> SELECT discounttype, 'Discount'=STR(discount, 7, 3) FROM discounts
4> GO
discounttype                             Discount
---------------------------------------- --------
Initial Customer                          10.500
Volume Discount                            6.700
Customer Discount                          5.000

(3 rows affected)
1>
2> drop table discounts;
3> GO
1>








12.20.STR
12.20.1.STR() converts a numeric value to a string
12.20.2.STR takes a numeric value and changes the data type to a char.
12.20.3.STR(float_expression, character_length, number_of_decimal_places)
12.20.4.SELECT STR(123.456789, 8, 4)
12.20.5.SELECT STR(1, 6, 4)
12.20.6.SELECT STR(1, 12, 4)