Viewing 15 posts - 2,131 through 2,145 (of 2,462 total)
Sean Lange (9/12/2013)
select SUM(Case when MyType = 2 then -1 * MyHours else MyHours end) as TotalHours
from #SomeTable
If I understand the original OP correctly (" If something has been credited,...
-- Itzik Ben-Gan 2001
September 12, 2013 at 9:57 am
Using the sample code above, I believe this will do the trick:
WITH billed_credited AS
(
SELECT CaseNum, MyHours, COUNT(MyHours) AS bc
FROM #SomeTable
GROUP by CaseNum, MyHours
)
SELECT SUM(x.Myhours) TotalHours
FROM #sometable st
CROSS APPLY...
-- Itzik Ben-Gan 2001
September 12, 2013 at 9:34 am
This is hard without DDL but assuming you cannot have this:
Case | Hours | Type
xxx | 3 | 1
xxx | 3 | 1
Or this:
Case | Hours | Type
xxx | 3...
-- Itzik Ben-Gan 2001
September 12, 2013 at 8:38 am
You should still be able to use UNION ALL in that scenario. Below is some code to create sample data similar to what I think you are dealing with. ...
-- Itzik Ben-Gan 2001
September 10, 2013 at 4:40 pm
Ditto what Jack said.
I always install sp_whoisactive and could not live without it (I run version 11.something). The most notable advantage over sp_who or sp_who2 is that you can...
-- Itzik Ben-Gan 2001
September 10, 2013 at 4:15 pm
Do you even need table1?
I have this:
Sample data (table1 included):
USE tempdb
GO
IF OBJECT_ID('tempdb..table1') IS NOT NULL DROP TABLE table1;
IF OBJECT_ID('tempdb..table2') IS NOT NULL DROP TABLE table2;
CREATE TABLE table1
(id int...
-- Itzik Ben-Gan 2001
September 10, 2013 at 2:44 pm
Any ideas on as to why the index rebuild task runs so quickly ?
Either have a few really small indexes, a blazing fast server or not all the indexes are...
-- Itzik Ben-Gan 2001
September 10, 2013 at 8:04 am
The short answer is: Yes, absolutely - there are several different ways.
I have done this kind of thing many times but need to better understand your requirement to...
-- Itzik Ben-Gan 2001
September 10, 2013 at 7:38 am
I'm assuming that "reversing columns and rows" you mean that the data needs to be pivoted.
There are a few ways to do this. The SSIS Pivot Transformation task will work...
-- Itzik Ben-Gan 2001
September 9, 2013 at 4:11 pm
Erland's article, "The Curse and Blessings of Dynamic SQL" (the link that OTF inlcuded) is the best I have ever read about DSQL.
Itzek Ben Gan's Microsoft® SQL Server 2012...
-- Itzik Ben-Gan 2001
September 6, 2013 at 2:52 pm
It seams to be working correctly for me as well...
-- Itzik Ben-Gan 2001
September 6, 2013 at 2:27 pm
I took what Sean put together and added a little more sample data (a second order number) and changed it up a little. If I am correct you need the...
-- Itzik Ben-Gan 2001
September 6, 2013 at 12:56 pm
Based on what I think you may be looking for I came up with:
WITH ddl_next_time_please(order_number, location, stop_type, stop_datetime, col) AS
(SELECT 1303927,'Whouse1 PUP',4394903,'2013-08-11 07:26:33.000',1UNION ALL
SELECT 1303927,'Store1 DRP',4394904,'2013-08-11 08:31:46.000', 2UNION ALL
SELECT...
-- Itzik Ben-Gan 2001
September 6, 2013 at 12:25 pm
I also love Paul's articles on APPLY and would second that suggestion. If you own or have access to Microsoft SQL Server 2012 High-Performance T-SQL functions by Itzek Ben-Gen there...
-- Itzik Ben-Gan 2001
August 30, 2013 at 10:38 am
Sean Lange (8/29/2013)
Alan.B (8/29/2013)
-- Itzik Ben-Gan 2001
August 29, 2013 at 1:15 pm
Viewing 15 posts - 2,131 through 2,145 (of 2,462 total)