Mega Code Archive

 
Categories / MSSQL Tutorial / String Functions
 

STR(float_expression, character_length, number_of_decimal_places)

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>