DECLARE @totalOrderCount INT BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. --SET NOCOUNT ON; SET @totalOrderCount = (SELECT COUNT(o.orders_id) FROM orders O WHERE o.orders_status = 4 AND DATEDIFF(DAY, o.date_purchased, GETDATE()) < 31) SELECT COUNT(o.orders_id) AS ordercount, (DATEDIFF(DAY, o.date_purchased, osh.orders_status_history_timestamp)) AS timetaken, (COUNT(o.orders_id) / @totalOrderCount) AS orderPC, @totalOrderCount AS orderTotal FROM orders O, dbo.tblPS_orders_status_history OSH WHERE o.orders_status = 4
|T-SQL: Why can you not SUM on a CASE statement, for crying out loud?||2||29|
|the term "Features Not Supported in the Next Version of SQL Server"||12||27|
|How would you modify a Stored Procedure in SQL Server 2008, so that the result set displays date field in format MM/DD/YYYY?||2||17|
|Whitepapers about how IO performance issue and cause spikes in CPU usage - Microsoft SQL Server||5||24|
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
23 Experts available now in Live!