Viewing 15 posts - 3,271 through 3,285 (of 4,087 total)
The problem is your UDF. It uses a loop within a loop. Look at the following article by Jeff Moden: Tally OH! An Improved SQL 8K “CSV...
March 23, 2012 at 9:51 am
Here is the version using NOT EXISTS.
WITH sq AS (
SELECT
RelationshipID
,ParentID
,ChildID
,RoleID
,StatusID
,CreateDate
,ActionID
,SelectOrNot
,ROW_NUMBER() OVER (PARTITION BY ChildID ORDER BY CreateDate) AS sort
FROM @RoleRanking AS rr
WHERE NOT EXISTS (
SELECT *
FROM @RoleRanking AS sub
WHERE sub.ChildID...
March 23, 2012 at 9:29 am
Chris Harshman (3/23/2012)
interesting problem, I think windowed functions work well here:
I've found that the windowed aggregates do a LOT of reads. You might be better off using a NOT...
March 23, 2012 at 9:20 am
Actually, the correct answer (assuming that your date fields are actual date fields) is that it's IMPOSSIBLE. Your expected output violates first normal form, because some of the rows...
March 22, 2012 at 9:32 am
Assuming that there is some date changed associated with each of the changes, use that to determine which change is more recent.
Option 2 is to update the source of the...
March 21, 2012 at 3:15 pm
Your criteria for which rows to update in your merge is incomplete. Since you forgot to include the DDL for your tables, sample data, expected results, and your current...
March 21, 2012 at 2:50 pm
Snargables (3/21/2012)
To be honest based on the above info i suppose my only issue w/ dynamic sql now is its readbility. It's just plain ugly.
A lot of that may depend...
March 21, 2012 at 1:42 pm
Someone else recently posted the exact same question, so this looks like a homework assignment. I suggest you try it on your own first.
Drew
March 21, 2012 at 8:47 am
captcooldaddy (3/20/2012)
also only the records who need to be update...removed left join
UPDATE t1 SET field1 = t2.field1
FROM Table1 t1 JOIN Table2 t2 ON
t2.id1 = t1.id1
AND t2.id2 =...
March 21, 2012 at 6:45 am
SGT_squeequal (3/20/2012)
Like other people suggest i would approach this using a pivot table, why does you boss object to a using pivot?
You do realize that that comment was made THREE...
March 21, 2012 at 6:40 am
captcooldaddy (3/20/2012)
UPDATE t1 SET field1 = t2.field1
FROM Table1 t1 JOIN Table2 t2 ON
t2.id1 = t1.id1
AND t2.id2 = t1.id2
where...
March 20, 2012 at 2:48 pm
Sean Lange (3/20/2012)
Drew I am curious if you have seen performance improvements with this multiple queries over the way I posted above. Or is it just personal preference?
Just to be...
March 20, 2012 at 10:56 am
I don't know MySQL either, but here is an approach using a Tally table. (I may have the syntax for REGEX wrong.)
SELECT Min(n) AS n
FROM YourTable
INNER JOIN Tally
ON Len(YourTable.YourString)...
March 20, 2012 at 10:26 am
It's easy to calculate the beginning of the month using the following function.
DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
You can then use that in your CASE expression or WHERE clause as appropriate.
Drew
March 20, 2012 at 10:11 am
With only one parameter, the dynamic SQL option is probably overkill. Here is another option that I have seen, which is fine with only one parameter.
IF @StaffID IS NULL...
March 20, 2012 at 9:25 am
Viewing 15 posts - 3,271 through 3,285 (of 4,087 total)