Viewing 15 posts - 1,741 through 1,755 (of 5,504 total)
A conditional SUM() based on a calendar table should do it.
March 27, 2011 at 1:39 pm
Would you please post the query in total as well as some more test data (including expected result)?
I'm confident it still can be done using a single CTE but I'd...
March 25, 2011 at 3:36 pm
What type of index did you create (clustered or non-clustered)? If it's the clustered index you still perform a table scan...
As a side note: why do you use VARCHAR(3) instead...
March 24, 2011 at 2:05 pm
Here's a slightly more complicated solution:
; WITH cte1 AS
(
SELECT
*,
DATEADD(mi,DATEPART(MINUTE,phonetime)/15 *15,DATEADD(hh,DATEDIFF(hh,0,Phonetime),0)) AS INTERVAL
FROM #PhoneCalls
), cte2 AS
(
SELECT
customerid,
INTERVAL,
ROW_NUMBER() OVER(PARTITION BY INTERVAL ORDER BY phonetime)-
ROW_NUMBER() OVER(PARTITION BY...
March 24, 2011 at 1:48 pm
If you have any further question or if you get stuck, please post back and I'm confident we can help you.
March 23, 2011 at 1:46 pm
From my point of view the query cost in the actual execution plan is even more misleading than the recommended indexes DTA comes up with (comparing apples and oranges, I...
March 23, 2011 at 11:46 am
There are several issue to be adressed:
1) it seems like the code snippet you posted is part of a dynamic SQL statement... (otherwise there's no reason to use two single...
March 23, 2011 at 11:35 am
When you're asking for the difference in months, SQL Server basically truncates the days of the dates you compare:
For example:
SELECT DATEDIFF(mm,'20101231','20110101')
SELECT DATEDIFF(mm,'20101201','20110131')
Both queries return the same value (1), since the...
March 22, 2011 at 1:58 pm
Glad I could help 😀
A second set of eyes helps a lot from time to time. Especially, if there's no mouth connected to it... 😉
March 21, 2011 at 1:01 pm
I don't think you need the UNION ALL in your CTE:
SELECT DTConID, TransactionType,
Sum(Convert(decimal(12,2),CASE WHEN AmtSign = '-' THEN 0 -...
March 21, 2011 at 12:27 pm
What is the order criteria to get the values for I_Serial?
Regarding getting ready to use sample data out of SSMS: please have a look at the first article referenced in...
March 20, 2011 at 2:48 pm
Please provide some sample data in the form "INSERT INTO ... SELECT ... UNION ALL" and your expected result based on the sample. Especially, please make sure to explain what...
March 20, 2011 at 1:18 pm
Here's a slightly different approach:
SELECT SUBSTRING(URLs,8,charindex('/',URLs+'/',8)-8) AS URLs
FROM @URLTable
March 19, 2011 at 3:36 pm
Step 1: Understand normalization. You could google for "database design normalization" to get several links to cover the basics.
Step 2: Understand the meaning and purpose of the data you're dealing...
March 19, 2011 at 10:57 am
Viewing 15 posts - 1,741 through 1,755 (of 5,504 total)