DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to force floating-point arithmetic on integer columns?

Execute the following SQL Server T-SQL script in SSMS Query Editor to force floating-point arithmetic by using 100.0 as a multiplier:

USE AdventureWorks;

 

SELECT   a.SalesOrderID,

         LineTotal='$'+CONVERT(varchar,convert(money,a.LineTotal,1)),

         PercentOfBase = CONVERT(DECIMAL(8,1),100.0 * a.OrderQty / b.TotalQty )

FROM     Sales.SalesOrderDetail a

         INNER JOIN (SELECT   SalesOrderID,

                        TotalQty = sum(OrderQty)

               FROM     Sales.SalesOrderDetail

               GROUP BY SalesOrderID) b

           ON a.SalesOrderID = b.SalesOrderID

ORDER BY a.SalesOrderID DESC,

         a.LineTotal DESC;

        

/*

SalesOrderID      LineTotal   PercentOfBase

75123             $159.00     33.3

75123             $21.98      33.3

75123             $8.99       33.3

75122             $21.98      50.0

75122             $8.99       50.0

75121             $35.00      33.3

75121             $34.99      33.3

*/

------------

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE