Viewing 15 posts - 4,741 through 4,755 (of 10,144 total)
Here's an alternative version which might be faster:
-- inline tally table has 7 rows = "6 months back"
;WITH iTally (n) AS (SELECT 0 UNION ALL SELECT 1 UNION ALL SELECT...
April 25, 2013 at 7:37 am
faheemahmad14 (4/25/2013)
thanks a lot for your prompt responsebut my requirement is not to use RowNumber or any other builtin function.
ROW_NUMBER is ideal for this - can you explain why you...
April 25, 2013 at 7:04 am
SELECT *
FROM #Table1 t1
CROSS APPLY (
SELECT TheDate = CONVERT(DATE,'01/'+LEFT(t1.Period,2)+'/'+RIGHT(t1.Period,4),103)
) x
OUTER APPLY (
SELECT *
FROM #Table2 t2
WHERE t2.Name = t1.Name
AND CONVERT(DATE,'01/'+LEFT(t2.Period,2)+'/'+RIGHT(t2.Period,4),103)
BETWEEN DATEADD(mm,-6,x.TheDate) AND x.TheDate
) y
April 25, 2013 at 6:47 am
Thanks Ron.
April 25, 2013 at 6:30 am
Abu Dina (4/25/2013)
Was waiting for your solution 😀 Nice!
Thank you! 🙂
April 25, 2013 at 6:11 am
Use the MAXRECURSION hint:
SELECT columns
FROM recursivecte
OPTION (MAXRECURSION 0); -- unlimited
In practice you might want to set it to a sensible value then increment, JIC your CTE loops.
April 25, 2013 at 5:59 am
-- check the query
SELECT *, UpdateMe = CASE WHEN a.SummaryType <> '0' THEN 'Y' ELSE 'N' END
FROM Table_A a
OUTER APPLY (
SELECT Result = (SUM(ai.Pass)/NULLIF(SUM(ai.VM_Id)*1.0,0)) * 100
FROM Table_A ai
WHERE...
April 25, 2013 at 5:51 am
-- Always run a SELECT first to see which rows are affected.
-- This query should return the rows you want to keep
SELECT MemberId, [Event], [Event Date]
FROM (
SELECT MemberId, [Event], [Event...
April 25, 2013 at 5:29 am
-- Since there are no matches on col1 between the two tables,
-- surely the starting point of the results table should reflect this?
t.col1 ...
April 25, 2013 at 4:44 am
iam777here4u (4/25/2013)
Sorry for the trouble. I hope below code will give better idea....
No worries. I like this better, can we use it? I think folks will find it easier to...
April 25, 2013 at 4:40 am
chalam87 (4/25/2013)
hi,before finding sub string you should trim the data otherwise it takes empty data also.
select id,SUBSTRING(Reverse(LTRIM(RTRIM(name))),3,1) from emp
;WITH Sampledata (id, name) AS (
SELECT 1 , 'srinivas ' UNION...
April 25, 2013 at 4:31 am
tom.wauters (4/25/2013)
April 25, 2013 at 4:19 am
iam777here4u (4/25/2013)
April 25, 2013 at 4:08 am
This works too:
WITH CteComplement AS (
SELECT *, CONVERT(numeric(14,2),Value) as Amount
FROM #Test
WHERE PathId IN (30,31)
)
-- Cte to add a flag to dataset, which indicates if the Amount <> 0 (flag =...
April 24, 2013 at 9:32 am
Tom, this CTE method does exactly the same thing - it reverses the order in which the two predicates are evaluated. The CTE's aren't evaluated in order, they're more or...
April 24, 2013 at 9:22 am
Viewing 15 posts - 4,741 through 4,755 (of 10,144 total)