Viewing 8 posts - 1 through 9 (of 9 total)
I think I've managed to get it. Here's the code I ended up using:
SELECTtbl2.iGroupId,
tbl1.vcSupplierId,
sum(tbl1.units) / tbl2.GroupUnits as share
FROM(SELECTROW_NUMBER() OVER(ORDER BY sq.vcItemSuppliers) iGroupId,
LEFT(sq.vcItemSuppliers,len(sq.vcItemSuppliers)-1) vcItemSuppliers,
sum(sq.itemunits) as GroupUnits
FROM(SELECToq.iItemId,
(SELECTt1.vcSupplierId+','
FROMtblOrder t1
WHEREt1.iItemId = oq.iItemId
FOR XML...
June 3, 2009 at 5:15 pm
I was able to run this, although I had to essientially run the basic group by query as the insert into tblOrder for the actual query to have any chance...
June 2, 2009 at 11:06 pm
Jason - thanks for the help. I'm running now. As long as it works optimization shouldn't be too much of an issue because I should only need to...
June 2, 2009 at 5:43 pm
It's true that a basic group by gives the correct results on the sample data, but I have many more items supplied by the same group of suppliers. If...
June 2, 2009 at 4:39 pm
Jason - that's an interesting result, thank you. I've never used For XML Path before, or anything with XML for that matter. From your results, I'm actually looking...
June 2, 2009 at 4:18 pm
Thanks GSquared. The temp table is useful, and the results are interesting. When I ran I found:
- dateadd function 1266ms
- floor 781ms
- string 1687ms
All times are CPU.
String...
April 7, 2009 at 10:19 am
That scenario was the limitation with Chris's original reply (triggered by my limited data sample). It seems that Mark's application of CTE's and joining on all non-date columns did...
January 27, 2009 at 3:58 pm
Thank you both for your assistance. It appears that Mark's solution works well (and better than the loop solution I had attempted). Chris - your solution worked exactly...
January 27, 2009 at 8:45 am
Viewing 8 posts - 1 through 9 (of 9 total)