Using rollup or grouping sets in a complicated manner
Dear all;
I have the following select statements that display data in the following manner below
select location, male, female from table_testthis gives me the results as following below
location Male Female
tx 1 2
NM 0 1
AK 1 2
tx 2 4this is what i want though however
location Male Female
Tx 3 6
Genders 9
AK 1 2
Genders 3
NM 0 1
Gender 1see inserts statment below
create table table_test
location varchar2(4000),
male number(20),
female number(10)
insert into table_test values('Tx', 1, 2);
insert into table_test values('NM', 0, 1);
insert into table_test values('AK', 1, 2);
insert into table_test values('Tx', 2, 4); all help is appreciated. thank you
Edited by: user13328581 on Oct 19, 2012 10:03 AM
select case group_id()
when 0 then location
else null
end location,
case group_id()
when 0 then to_char(sum(male))
else 'Genders'
end male,
case group_id()
when 0 then sum(female)
else sum(male) + sum(female)
end female
from table_test t
group by grouping sets((location),(location))
order by t.location,
group_id()
LOCATION MALE FEMALE
AK 1 2
Genders 3
NM 0 1
Genders 1
Tx 3 6
Genders 9
6 rows selected.
SQL> SY.
Similar Messages
-
Has anyone used grouping sets or perhaps rollup function
I am trying to do a rollup query ....to sum up sales based on an
account number you would think pretty simple.....so here is the
query I wrote
SELECT broker_number
account_number , ACCOUNT_NAME ,
to_char( SUM ( FACTORY_NET_AMT ) , '9,999,999,999') sales$
FROM broker_account_expanded
WHERE product_level = 'BRND'
and product_level_Code not in ( select PROD_CATEGORY_CD from
genesis.tFIN_BRAND )
AND PRODUCT_LEVEL_CODE = '100515'
group by GROUPING SETS (
( broker_number , account_number , account_name ))
however I am getting the following error
SQL> /
group by GROUPING SETS (
ERROR at line 9:
ORA-00933: SQL command not properly ended
Any ideas ?
Thank's
Sameer HandaI think correct would be:
GROUP BY ROLLUP (broker_number , account_number , account_name ) -
Average getting calculated incorrectly using group by grouping sets
Hi All
I am using the group by grouping sets to calulate the running totals of aggregate functions like count, sum & avg.
I get the grand totals of count & sum perfectly right but with avg i am getting the averages incorrectly as the number of rows retrieved by the select query increases.
With few rows (3-4) the averages are round about correct but when the number of rows retreived increase say 5 or more than 5 I get absurd average figures
Here is the query I am using
<code>
select AGENT.NAME,
sum(decode(ACTIVITY.status,'New',1)) cnt,
sum(decode(ACTIVITY.status,'Open',1)) sumopen ,
round(avg( decode (ACTIVITY.status,'Open',ACTIVITY.STATUS_DIFF)),0) avgopen,
sum(decode(ACTIVITY.status,'Sent',1)) sumsent,
round(avg( decode (ACTIVITY.status,'Sent',ACTIVITY.STATUS_DIFF)),0) avgsent,
sum(decode(ACTIVITY.status,'Dead',1)) sumdead,
round(avg( decode (ACTIVITY.status,'Dead',ACTIVITY.STATUS_DIFF)),0) avgdead
from ACTIVITY, REQUEST , AGENT
where
REQUEST.DEALER_NUMBER = AGENT.DEALER_ID
and REQUEST.CONFIRMATION='Y'
and REQUEST.REQUEST_ID = ACTIVITY.REQUEST_ID
and REQUEST.REQUEST_TYPE='B'
and ACTIVITY.ACTIVITY_DATE between to_date('2006-01-01 ','YYYY-MM-DD') and to_date('2006-08-31','YYYY-MM-DD')
group by grouping sets((AGENT.DEALER_ID,AGENT.NAME), ())
</code>
Do let me know your suggestions
RegardsNot sure but may be
See below query
SQL> SELECT deptno,ROUND(AVG(sal))
2 FROM emp
3 GROUP BY ROLLUP(deptno,sal+rownum);
DEPTNO ROUND(AVG(SAL))
10 1300
2450
5000
"2917" ---Sub total
20 800
1100
2975
3000
3000
"2175" ---Sub total
30 950
1250
1250
1500
1600
2850
"1567" ---Sub total
"2073" ----Grand total
18 rows selected.
Now you want
SQL> SELECT (2917+2175+1567)/3 FROM dual;
(2917+2175+1567)/3
2219.66667
While it is
SQL> SELECT ROUND(SUM(sal)/COUNT(*)) FROM emp;
ROUND(SUM(SAL)/COUNT(*))
2073Khurram -
Isse with using Grouping Sets in SQL Server 2008 R2
Hi,
I created a query in SQL Server 2012 using grouping sets that works fine. When I try to use the same query in SQL Server 2008 I get an error ("Inccorrect syntax near SETS").
I researched using grouping sets in 2008 and didn't see any issue with my query. What is different in grouping sets 2008 vs 2012?
SELECT tl.ClientRegionCd as [Client Region Code] , tl.ClientRegionDesc as [Region Name], count(tl.CompleteICN) as [Trauma Letters Sent]
from TORT_Trauma_Letters tl
Where CONVERT(VARCHAR(26), tl.SecondNoticeSent, 23) between '2014-06-12' and '2014-06-12'
GROUP BY GROUPING SETS((tl.ClientRegionCd, tl.ClientRegionDesc), ())
StacieCheck this blog post as how to deal with date ranges
http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/16/bad-habits-to-kick-mishandling-date-range-queries.aspx
For your result you can simply achieve your result with UNION ALL, e.g.
select Client, Region, Letters
from myTable
UNION ALL
select NULL, NULL, SUM(letters) as Letters
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to sort specific column when using GROUPING SETS in SQL Server?
If I remember correctly, in SQL Server, it is not recommended to use "ORDER BY" when there's already a GROUP BY GROUPING SETS.
I have two columns: [UPC#] & [Description] both are varchar.
My grouping sets is like this:
GROUP BY
GROUPING SETS
([UPC],[Description])
I don't have 'ORDER BY' but it's automatically sorting the Description column.
If I added a 3rd column, sum(Qty), then it doesn't sort by Description anymore. But if I added
ORDER BY [Description]
then the grand total of sum(Qty) will be at the first row instead of the last.
Is there a way to sort the Description column and still let the grand total of sum(Qty) be at the last row instead?
Thanks.Yes, it works.
Thank you.
Could you kindly explain the logic?
I don't quite understand the "= 3 THEN 1 ELSE 0" part.
Is the #3 mean the column index 3?
GROUPING_ID returns a bit mask value depending on number of columns grouped in the result
So when you do GROUPING_ID(([UPC]),([Description]))
it has two columns UPC and Description so bit mask will be as follows
0 ie 00 for rows grouped by both UPC and Description fields
1 ie 01 for rows grouped by UPC ie UPC subtotals
2 ie 10 for rows grouped by Description ie Description subtotals
3 ie 11 for rows not grouped by both columns ie Grand total
see
http://msdn.microsoft.com/en-IN/library/bb510624.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Oracle group by 10 minutewith interval using rollup
HI,
PLEase check the below query
When I am trying to run this query ALONE
Select TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''||substr(c.TIME,10,3) ||':'||
LPAD (( TO_CHAR (c.TIME, 'MI') - MOD (TO_CHAR (c.TIME,'MI'), 10)),2,'0') slice from ILCL c
OUPUT IA M GETTTING:
08/07/2011 10:20
08/07/2011 10:30
08/07/2011 10:40
But I run the same query in the below and using that column with group by it is throwing error in group by clause
BECAUSE USING ROllUP
Actually the C.time data type is timestamp
Data base column structure:
COLUMN DATATYPE FORMAT-----Data loaded in the data base
TIME ------(TIMEStTAMP) ---07-AUG-11 10.29.27.746000000 AM
SELECT 'R' TYPE, c.date,
substr(c.Time,27,29) am r pm,
TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''||substr(c.TIME,10,3) ||':'||
LPAD (( TO_CHAR (c.TIME, 'MI') - MOD (TO_CHAR (c.TIME,'MI'), 10)),2,'0') slice,
-- TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''|| substr(c.TIME,10,6) time_slice,
CASE
WHEN type1 = 'py'
THEN 'pyS'
WHEN type1 = 'PV'
THEN 'PV'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
THEN 'pmg'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
THEN 'ACT'
END CT,
CASE
WHEN type1 = 'py'
AND e.type2 = 'EFAUOT'
THEN 'EFAUTO'
WHEN type1 = 'py'
AND e.type2 = 'CA_AUTO'
THEN 'CARD_AUTOFILL'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NOT NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-CHANGED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-REMOVED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NOT NULL
AND remove_from_service_code_list IS NULL
THEN 'p_added'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type = 'H'
THEN 'ACT_TECH'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type <> 'H'
THEN 'A_cR'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'N'
THEN 's_iL'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'Y'
THEN 'spkg'
ELSE type2
END type2,
CASE
WHEN event_status_type = 'scss'
THEN 'scss'
ELSE 'FL'
END STS_type,
COUNT (DISTINCT e.ce),
ROUND (AVG (e.elapsed_msec) / 1000) txn_time,
ROUND (AVG (c.elapsed_msec)/1000) call_time
FROM
---ivr_transaction h,
ILC1 e,
ILCL c,
ILEW w,
ILEp p
WHERE
---e.CD = h.CD
w.CD(+) = e.CD
-- AND w.event_id(+) = e.event_id
AND p.CD(+) = e.CD
---- AND p.event_id(+) = e.event_id
AND p.ce(+) = e.ce
AND w.ce(+) = e.ce
AND c.CD = e.CD
AND c.ci = e.ci
--AND e.ce = h.ce
AND e.CD = TRUNC (SYSDATE - 1)
AND c.TIME <> TRUNC (SYSDATE)
AND ( (e.type1 = 'py')
OR (type1 = 'PV')
OR ( type1 = 'pmg'
AND e.type2 = 'mfy'
OR (type1 = 'epmt'
AND e.type2 = 'AT'
GROUP BY 'TCR',
c.CD,
substr(c.TIME,27,29),
TO_CHAR(TRUNC(c.TIME),'MM/DD/YYYY')||''||substr(c.TIME,10,3) ||':'||
LPAD (( TO_CHAR (c.TIME, 'MI') - MOD (TO_CHAR (c.TIME,'MI'), 10)),2,'0'),
--TO_CHAR (c.TIME, 'MI'),
CASE
WHEN type1 = 'py'
THEN 'pyS'
WHEN type1 = 'PV'
THEN 'PV'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
THEN 'pmg'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
THEN 'ACT'
END,
ROLLUP (CASE
WHEN type1 = 'py'
AND e.type2 = 'EFAUOT'
THEN 'EFT_AUTO'
WHEN type1 = 'py'
AND e.type2 = 'CA_AUTO'
THEN 'CARD_AUTOFILL'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NOT NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-CHANGED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-REMOVED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list1 IS NOT NULL
AND list1 IS NULL
THEN 'p_added'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type = 'H'
THEN 'ACT_TECH'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type <> 'H'
THEN 'A_cR'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'N'
THEN 's_iL'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'Y'
THEN 'sp'
ELSE type2
END),
ROLLUP (
CASE
WHEN event_status_type = 'scss'
THEN 'scss'
ELSE 'FL'
END)
WHEN I A M TRYING T TO EXCUTE ABOVE QUERY IT SHOING ERROR AT GEOUP BY CLAUSE AS HIGHLITED SAYS (ORA00900------Invalid sql statement) when I cooment one of the roll up sin group by clause it is getting the data but need to have two rollups all case statements are working fine no issues with those on problem with highlited ones or in the bold.Please give me sugeestions ASAP
Thanks
SatyaHi Kulash,
Very very Thanks for the quick reply .
SELECT SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
, 1
, 15
) || '0' AS slice
FROM dual;
This query works fine if we run individually but the same is not runing in the group by clause
Hi Kulash,
Very very Thanks for the quick reply .
SELECT SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
, 1
, 15
) || '0' AS slice
FROM dual;
This query works fine if we run individually but the same is not runing in the group by clause .i think because of the rollups . could you pleasae tell me is there any change needed in the group by clause if we are using rollups.Because it showing error in the group by clause as a Invalid sql statement (ora00900)
group by
c.CD,
substr(c.TIME,27,29),
SUBSTR ( TO_CHAR (c.time, 'MM/DD/YYYY HH24:MI')
, 1
, 15
) || '0'
CASE
WHEN type1 = 'py'
THEN 'pyS'
WHEN type1 = 'PV'
THEN 'PV'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
THEN 'pmg'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
THEN 'ACT'
END,
ROLLUP (CASE
WHEN type1 = 'py'
AND e.type2 = 'EFAUOT'
THEN 'EFT_AUTO'
WHEN type1 = 'py'
AND e.type2 = 'CA_AUTO'
THEN 'CARD_AUTOFILL'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NOT NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-CHANGED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-REMOVED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list1 IS NOT NULL
AND list1 IS NULL
THEN 'p_added'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type = 'H'
THEN 'ACT_TECH'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type 'H'
THEN 'A_cR'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'N'
THEN 's_iL'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'Y'
THEN 'sp'
ELSE type2
END),
ROLLUP (
CASE
WHEN event_status_type = 'scss'
THEN 'scss'
ELSE 'FL'
END)
---------------------------TOTAL QUERY----------------------------
SELECT 'R' TYPE, c.date,
substr(c.Time,27,29) am r pm,
SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
, 1
, 15
) || '0' slice,
CASE
WHEN type1 = 'py'
THEN 'pyS'
WHEN type1 = 'PV'
THEN 'PV'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
THEN 'pmg'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
THEN 'ACT'
END CT,
CASE
WHEN type1 = 'py'
AND e.type2 = 'EFAUOT'
THEN 'EFAUTO'
WHEN type1 = 'py'
AND e.type2 = 'CA_AUTO'
THEN 'CARD_AUTOFILL'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NOT NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-CHANGED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-REMOVED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NOT NULL
AND remove_from_service_code_list IS NULL
THEN 'p_added'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type = 'H'
THEN 'ACT_TECH'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type 'H'
THEN 'A_cR'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'N'
THEN 's_iL'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'Y'
THEN 'spkg'
ELSE type2
END type2,
CASE
WHEN event_status_type = 'scss'
THEN 'scss'
ELSE 'FL'
END STS_type,
COUNT (DISTINCT e.ce),
ROUND (AVG (e.elapsed_msec) / 1000) txn_time,
ROUND (AVG (c.elapsed_msec)/1000) call_time
FROM
---ivr_transaction h,
ILC1 e,
ILCL c,
ILEW w,
ILEp p
WHERE
---e.CD = h.CD
w.CD(+) = e.CD
-- AND w.event_id(+) = e.event_id
AND p.CD(+) = e.CD
---- AND p.event_id(+) = e.event_id
AND p.ce(+) = e.ce
AND w.ce(+) = e.ce
AND c.CD = e.CD
AND c.ci = e.ci
--AND e.ce = h.ce
AND e.CD = TRUNC (SYSDATE - 1)
AND c.TIME TRUNC (SYSDATE)
AND ( (e.type1 = 'py')
OR (type1 = 'PV')
OR ( type1 = 'pmg'
AND e.type2 = 'mfy'
OR (type1 = 'epmt'
AND e.type2 = 'AT'
GROUP BY 'TCR',
c.CD,
substr(c.TIME,27,29),
SUBSTR ( TO_CHAR (SYSDATE, 'MM/DD/YYYY HH24:MI')
, 1
, 15
) || '0',
--TO_CHAR (c.TIME, 'MI'),
CASE
WHEN type1 = 'py'
THEN 'pyS'
WHEN type1 = 'PV'
THEN 'PV'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
THEN 'pmg'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
THEN 'ACT'
END,
ROLLUP (CASE
WHEN type1 = 'py'
AND e.type2 = 'EFAUOT'
THEN 'EFT_AUTO'
WHEN type1 = 'py'
AND e.type2 = 'CA_AUTO'
THEN 'CARD_AUTOFILL'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NOT NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-CHANGED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list IS NULL
AND remove_from_service_code_list IS NOT NULL
THEN 'pmg-REMOVED'
WHEN type1 = 'pmg'
AND e.type2 = 'mfy'
AND list1 IS NOT NULL
AND list1 IS NULL
THEN 'p_added'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type = 'H'
THEN 'ACT_TECH'
WHEN type1 = 'epmt'
AND e.type2 = 'AT'
AND c.campaign_type 'H'
THEN 'A_cR'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'N'
THEN 's_iL'
WHEN type1 = 'PV'
AND type2 = 'SPORT'
AND p.flag = 'Y'
THEN 'sp'
ELSE type2
END),
ROLLUP (
CASE
WHEN event_status_type = 'scss'
THEN 'scss'
ELSE 'FL'
END) -
Is this a bug with grouping sets?
Version is Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SQL> with data as
2 (select rownum r, 'X' x, 1 n from dual connect by rownum <= 10)
3 select x
4 , sum(n) s
5 , (select sum(1) from dual where dummy = x) t
6 from data
7 group by grouping sets (x, ())
8 /
X S T
X 10 1
10
SQL> Shouldn't the superaggregate row have a 1 in the T column?Here's your QUERY with the addition of the GROUPING() function:
SQL> WITH data AS
2 (
3 SELECT rownum r
4 , 'X' x
5 , 1 n
6 FROM dual
7 CONNECT BY rownum <= 10
8 )
9 SELECT GROUPING(x)
10 , x
11 , sum(n) s
12 , (SELECT sum(1) FROM dual WHERE dummy = x) t
13 FROM data
14 GROUP BY GROUPING SETS (x, ())
15 ;
GROUPING(X) X S T
0 X 10 1
1 10In this case the value for X is null because it's a subtotal row. If you look at the execution plan for this statement:
PLAN_TABLE_OUTPUT
SQL_ID gumphwvgumqc4, child number 0
WITH data AS ( SELECT rownum r , 'X' x , 1 n FROM
dual CONNECT BY rownum <= 10 ) SELECT /*+gather_plan_statistics*/ x
, sum(n) s , (SELECT sum(1) FROM dual WHERE dummy = x) t FROM
data GROUP BY GROUPING SETS (x, ())
Plan hash value: 1718326399
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | 1 | | 2 |00:00:00.01 | 0 | | | |
| 1 | SORT AGGREGATE | | 2 | 1 | 2 |00:00:00.01 | 4 | | | |
|* 2 | TABLE ACCESS FULL | DUAL | 2 | 1 | 1 |00:00:00.01 | 4 | | | |
| 3 | SORT GROUP BY ROLLUP | | 1 | 1 | 2 |00:00:00.01 | 0 | 2048 | 2048 | 2048 (0)|
| 4 | VIEW | | 1 | 1 | 10 |00:00:00.01 | 0 | | | |
| 5 | COUNT | | 1 | | 10 |00:00:00.01 | 0 | | | |
| 6 | CONNECT BY WITHOUT FILTERING| | 1 | | 10 |00:00:00.01 | 0 | | | |
| 7 | FAST DUAL | | 1 | 1 | 1 |00:00:00.01 | 0 | | | |
Predicate Information (identified by operation id):
2 - filter("DUMMY"=:B1)The value for X is being bound to the subquery. If X is null this won't return any rows (I'm sure you knew that :) ). I would say this is expected albeit confusing behavior. You get the same results if you use CUBE or ROLLUP as well. -
User Configuration/Policies/Administrative Templates
- Using Office 2013 group policy template to define Trusted Locations and Template Locations doesn't work
Microsoft Word 2013/Word Options/Security/Trust Center/Trusted Locations
- Allow Trusted Locations on the network:
Enabled
- Trusted Location #1:
Enabled
Path: //server/sharedfoldername [Edit: Path:
\\server\sharedfoldername]
Date: June 10, 2013
Description: Trusted Location
Allow sub folders: Enabled
The policy appears to apply to the client correctly by adding the following registry key and values:
HKEY_CURRENT_USER\Software\Policies\Microsoft\office\15.0\word\security\trusted locations\location1
allowsubfolders: 1
date: June 10, 2013
Description: Trusted Location
Path: //server/sharedfoldername [Edit: Path:
\\server\sharedfoldername]
However, when you open Word Options/Trust Centre/Trust Centre Settings…/Trusted Locations
There are no trusted locations listed under ‘Policy Locations’
I have tried setting similar settings for setting the Shared Templates folder location and just like the trusted locations policy, the registry keys are created properly in HKEY_CURRENT_USER\Software\Policies however word doesn’t
seem to recognize these either.
This used to work flawlessly using the administrative templates for Word 2007 and 2010. Has anyone been able to get these policies to apply successfully, or know why office doesn’t recognize these settings from the Policies registry
Key?This would have been an easy solution to the issue. Unfortunately it isn't the problem. This question was originally posted on another Microsoft site and
was transferred here and when it was transferred the path's changed from the original post:
\\server\sharedfodlername to //server/sharedfoldername. (I will edit the question to show up as it did in the original post) Not sure how that happened. This
is still an issue that I haven't been able to get working correctly.
As it turns out the 'New from Template' interface Word 2013 has developed is very bulky with large thumbnails and is not very customizable nor practical for an office
that has a large number of templates. Because I am unsatisfied with the display and performance of the 'New' template chooser I sought after a solution to change the way word creates a document from a template in another thread:
http://answers.microsoft.com/en-us/office/forum/office_2013_release-word/how-can-you-change-the-display-of-templates-in/d49194b9-a6b4-4768-8502-7d7b50e9dd65 working through this issue with Jay we were able to develop
some VB script with handles a very large number of templates in a list view and it works much faster than the built-in Word interface. The above thread is how I've worked around trying to define a shared template location and I am quite happy with it. -
Using a security group to add members to the collection question
Hi,
I have a collection created in SCCM 2007 that is using a security group for membership. So I added a computer to the security group in AD but when I go to SCCM and click on the collection I dont see the computer in the collection. Should it show here or
because it is a security group based membership will it not show the members?
THanks!Details from Active directory are added to SCCM database through discovery methods. Please ensure that AD security group discovery and AD system discovery are enabled in the primary site. If they are enabled, check the frequency set for these discovery
methods. Once you added these computers to the AD group, you need to wait till the next discovery cycle before it appears in SCCM collections. Till that point, SCCM database will not have information about the group memberships of these computers -
Using a dropdown to set a radio button
I've been searching and searching in vain, trying many different things can I cannot seem to find an answer already or stumble on similar code to help.
I've got a dropdown, then when you select different values set different fields on the form. That part works fine stuff like this in the custom validate:
if (event.value == "Thing1") {
this.getField("DESC01").value = "Words that fill in a desciption box.";
this.getField("DESC02").value = "More words that fill in another descrption box";
this.getField("F_SKILL1").value = "1";
this.getField("RB_SKILL1").isBoxChecked(1);
this.getField("F_SKILL2").value = "1";
this.getField("F_SKILL3").value = "1";
} else if (event.value == "Thing2") {
this.getField("DESC01").value = "Different words that fill in a desciption box.";
this.getField("DESC02").value = "More different words that fill in another descrption box";
this.getField("F_SKILL4").value = "1";
this.getField("RB_SKILL1").isBoxChecked(0);
this.getField("F_SKILL5").value = "1";
this.getField("F_SKILL6").value = "1";
etc, etc. I've got a few different else ifs but they all follow this kind of format. There is are also radio button next to the skills on the sheet to visually display that skill is known. So I'd like to turn that radio button on. My isBoxChecked isn't working, and I expect that's because it doesn't work that way. I have a lot of radio buttons on the form, but they all have 1 choice in them none are groups. Again, I'm using this as a visual display that SKILLX is known. The area I've dropped the radio button onto the sheet is a very small circle which is why I am trying to use a radio button as it's visually similar.
If there is a better solution to what I'm trying to do I'm happy to try that, or if someone can tell me what I'm doing wrong that'd be super
Thanks!Not quite sure I'm getting what you are laying down...
So in the dropbox, under options I should set the export value of Thing1 choice to RB_SKILL1 and then in my validate I should include this.getField("RB_SKILL1").value = 'Yes' ?
Or I should just set the export value of Thing1 to this.getField?
Thanks
Oh, using a check box I was able to get this working using the export values set for Thing1 option, most excellent! Thank you very much! -
How to make use of the 'Groups' in Screen Layout?
Hi All,
I have a screen with 10 input fields (F1, F2, .. F10).
I set the 'Groups' attribute in the screen layout to 'DIS'.
How could I make use of this 'Groups' attribute so that when I loop the screen, I will only disable fields with the 'Groups' attribute set to 'DIS'? Thanks
I tried the following codes, but it's not working:
LOOP AT SCREEN.
IF SCREEN-GROUPS IS NOT 'DIS'.
SCREEN-INPUT = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
It says ==> The data object 'SCREEN' does not have a component called 'GROUPS'.In the Attributes of a screen field, there is an attribute called "Groups". This has 4 options for input (4 text boxes)
SCREEN has 4 fields GROUP1, GROUP2, GROUP3 and GROUP4.
The first text box under Groups attribute corresponds to SCREEN-GROUP1,
2nd text box for SCREEN-GROUP2
3rd text box for SCREEN-GROUP3
4th text box for SCREEN-GROUP4
Hope this helps.
Thanks,
Balaji -
Exchange 2010 Unable to Assign Full Access Permissions using a Security Group
I've been running into this issue lately. I cannot seem to use groups to allow full access to mailboxes. When I add them from the EMC, it will show up when you go to "Manage Full Access Permission...". After waiting a day and even restarting
the Information Store service, the permissions do not take effect. When I view the msExchDelegateListLink attribute of the mailbox account, the group is not listed.
When I grant a user full permission, it works and updates the attribute. However, on occasion when I revoke the full access permission for a user is doesn't always remove that user from the msExchDelegateListLink attribute. So the mailbox
will still appear in Outlook, but the user isn't able to see new emails.
Any ideas on what may be going wrong?
Environment:
Exchange Server 2010 SP1 Standard
Windows Server 2008 R2 Standard
Outlook 2010 SP1 (tried without SP1 as well)
I was looking over Add-MailboxPermission on Technet (http://technet.microsoft.com/en-us/library/bb124097.aspx) and I noticed that it doesn't mention adding groups. Is this not possible?I never got a proper fix.
I worked around it by creating a script which gets the members of an AD Mail Enabled security group, and updates the full access based on the groups members.
Here's a script I'm running every hour which updates permissions. It's probably not the most efficient script ever, but it works. It has several benefits
1. Managers of the distribution group can add/remove mailbox members using OWA or through the address list
2. New members of groups are added to FULL Access Permissions
3. Members removed from the groups are removed from FULL access permissions
4. Automapping works :)
5. Maintains a log of access added / removed / time taken etc.
Obviously I have had to remove domain related information, replace with whatever your domain requirements are, and PLEASE debug it properly in your environent first, don't complain to me if it wipes out a load of access for you or something like that!
It takes about 5 minutes to run in my environement. Some formatting seems to have got messed up on here, sorry. I hope it is of use!
# Mailbox Permissions Setter for Exchange #
# v1.1 #
# This script will loop through all mailboxes in Exchange and find any where #
# the type is 'SHARED'. These should be determined to be a GROUP/SHARED mailbox #
# and access to these mailboxes are controlled by a single ACL, e.g. 'ACL_Shared_Mailbox'. #
# This script will add any members of these ACLs directly to the Full Access Permissions #
# of the mailbox and also remove them if they no longer need the access. #
# Script created by Jon Read, Technical Administration
# Recent Changes
# 15/11/2012
# 1.1 Added exclusions for ACLs that we don't want automapping to happen for
# 12/11/2012
# 1.0 Initial script
#Do not change these values
Add-PSSnapin *Ex*
$starttime = Get-Date
$logfile = "C:\accesslog.txt"
$logfile2 = "C:\accesslog2.txt"
$totaladditionstomailboxes = 0
$totalremovalsfrommailboxes = 0
$totalmailboxesprocessed = 0
$totalmailboxesskipped = 0
# Exclude any ACLs that shouldn't be processed here if they are used for a non-standard purpose and
# we don't want FULL access mapping to happen. Seperate array values with commas
$ExcludedACLArray = "DOMAIN\ACL_ExcludedExample"
Write-Output " " >> $logfile
Write-Output " " >> $logfile
Write-Output "#----------------------------------------------------------------#" >> $logfile
Write-Output "# Mailbox Permissions Setter for Exchange #" >> $logfile
Write-Output "# v1.1 #" >> $logfile
Write-Output "#----------------------------------------------------------------#" >> $logfile
Write-Output " " >> $logfile
Write-Output " " >> $logfile
Write-output "Start time $starttime ">> $logfile
Write-Output " " >> $logfile
Write-Output " " >> $logfile
# Set preferred DCs and GCs
$preferredDC = "preferredDC.domain"
$preferredGC = "preferredGC.domain"
Write-Output " PreferredDC = $preferredDC ">> $logfile
Write-Output " PreferredGC = $preferredGC " >> $logfile
Set-ADServerSettings -PreferredGlobalCatalog $preferredGC -SetPreferredDomainControllers $preferredDC
# The first part of this will ADD permissions to the mailbox, reading from an associated ACL.
# Check for all mailboxes where the type is SHARED. These are the only ones we would
# want to apply group mailbox permissions to.
foreach ($mailbox in get-mailbox -resultsize "unlimited" | where-object {$_.RecipientTypeDetails -eq "SharedMailbox"})
$totalmailboxesprocessed = $totalmailboxesprocessed + 1
Write-Output " " >> $logfile
Write-Output " " >> $logfile
Write-Output "|-------------------------------------------------------" >> $logfile
Write-Output "| MAILBOX ADDITIONS: $mailbox " >> $logfile
Write-Output "|-------------------------------------------------------" >> $logfile
$mailbox=$mailbox.ExchangeGuid.ToString()
# For each of them, get the distribution list applied to the mailbox (Starting DOMAIN\ACL_)
# We then need it to be turned into a string to use later.
#Declared $changes as 0. if this is set to 0 at the end of the mailbox job, we know no changes were made.
$changes = 0
foreach ($distributiongroup in get-mailbox $mailbox | Get-MailboxPermission | Where-Object {$_.User -like "DOMAIN\ACL_*" })
$skipACL = 0
#Get the distribution group and put the name in a useable format
$distributiongroup=$distributiongroup.user.tostring()
Write-Output "Found ACL $distributiongroup" >> $logfile
# Check if this distribution group needs to be excluded and if it shouldn't be processed
# then move onto the next ACL. This will stop FULL access being granted if the mailbox is
# used for a non-standard purpose. See the start of this script
# for where these are excluded (ExcludedACLArray)
foreach ($ACL in $ExcludedACLArray )
if ($distributiongroup -eq $ACL)
$skipACL = 1
Write-Output "ACL $distributiongroup is excluded so skipping mailbox " >> $logfile
$totalmailboxesskipped = $totalmailboxesskipped + 1
if ($skipACL -eq 0)
# Get each user in this group and for each of them, add try to add them to full access permissions.
foreach ($user in Get-DistributionGroupMember -identity $distributiongroup)
# Get the user to try, convert to DOMAIN\USER to use shortly
$user="DOMAIN\" + $user.alias.ToString()
# Check to see if the user we have chosen from the ACL group already exists in the full access
# permissions. If they do, set $userexists to 1, if they do not, leave $userexists set to 0.
# Set $userexists to 0 as the default
$userexists = 0
foreach ($fullaccessuser in get-mailbox $mailbox | Get-MailboxPermission)
# See if the user exists in the mailbox access list.
# Change $fullaccessuser to a useable string (matching $user)
$fullaccessuser=$fullaccessuser.user.tostring()
if ($fullaccessuser -eq $user)
$userexists=1
# Break out of foreach if the user exists so we don't unnecessarily loop
break
# Now we know if the user needs to be added or not, so run code (if needed) to add
# the user to full access permissions
if ($userexists -eq 0)
Add-MailboxPermission $mailbox –user $user –accessrights "FullAccess"
Write-Output "Added $user " >> $logfile
$changes = 1
$totaladditionstomailboxes = $totaladditionstomailboxes + 1
#Now repeat for other users in the ACL
#if changes were 0, then log that no changes were made
if ($changes -eq 0)
Write-Output "No changes were made." >> $logfile
Write-Output " " >> $logfile
Write-Output " " >> $logfile
Write-Output "---------------------------------------------------------------------------------" >> $logfile
Write-Output " FINISHED ADDING PERMISSIONS" >> $logfile
Write-Output "---------------------------------------------------------------------------------" >> $logfile
Write-Output " " >> $logfile
# The second part of this will REMOVE permissions from the mailbox, reading from an associated ACL.
## Check for all mailboxes where the type is SHARED. These are the only ones we would
## want to apply group mailbox permissions to.
foreach ($mailbox in get-mailbox -resultsize "unlimited" | where-object {$_.RecipientTypeDetails -eq "SharedMailbox"})
Write-Output " " >> $logfile
Write-Output " " >> $logfile
Write-Output "|-------------------------------------------------------" >> $logfile
Write-Output "| MAILBOX REMOVALS : $mailbox " >> $logfile
Write-Output "|-------------------------------------------------------" >> $logfile
$mailbox=$mailbox.ExchangeGuid.ToString()
#Declared $changes as 0. if this is set to 0 at the end of the mailbox job, we know no changes were made.
$changes = 0
# For the current mailbox, get a list of all users with FULLACCESS, and then for each of them
# check if they exist in the ACL
foreach ($fullaccessuser in get-mailbox $mailbox | Get-MailboxPermission | Where-Object {$_.Accessrights -like "FullAccess" })
# Get the security identifier (SSID) of the FULLACCESS user to store for later.
$fullaccessuserSSID=$fullaccessuser.user.SecurityIdentifier.ToString()
$fullaccessuser=$fullaccessuser.User.ToString()
#If user needs to be excluded then skip this bit
#Users added or removed will only start with 07 (07$, 07T, so only run if the user starts with this.
#This stops it trying to remove NT AUTHORITY\SELF and other System entries
if ($fullaccessuser -like "DOMAIN\07*")
# Set $userexists to be 0. if we find the use user needs to remain, then change it to 1.
$userexists=0
# Check if this user exists in the ACL, if not, remove.
foreach ($distributiongroup in get-mailbox $mailbox | Get-MailboxPermission | Where-Object {$_.User -like "DOMAIN\ACL_*" })
$distributiongroup=$distributiongroup.user.tostring()
#Write-Output "Found associated distribution group $distributiongroup" >> $logfile
# Get each user in this group and for each of them, See if it matches the user in the mailbox.
foreach ($user in Get-DistributionGroupMember -identity $distributiongroup)
# Get the user to try, convert to DOMAIN\USER to use shortly
$userguid = $user.Guid.ToString()
$user="DOMAIN\" + $user.alias.ToString()
if ($fullaccessuser -eq $user)
$userexists=1
#we have found the user exists so no need to continue
break
# If userexists = 0, then they are NOT in the ACL, and should be removed from
# the full access permissions. Run the code to remove them from full access.
#CONVERT FULLACCESSUSER TO GUID AND REMOVE $FULLACCESSUSERGUID NOT $USERGUID
if ($userexists -eq 0)
Remove-MailboxPermission -Identity $mailbox –user $fullaccessuserSSID –accessrights "FullAccess" -Confirm:$false
Write-Output "Removed $fullaccessuser " >> $logfile
$changes = 1
$totalremovalsfrommailboxes = $totalremovalsfrommailboxes + 1
# if changes = 0, no changes were made to this mailbox, so log this fact.
if ($changes -eq 0)
Write-Output "No changes were made." >> $logfile
#Put the time in a displayable format
$endtime = Get-Date
$runtime = $endtime - $starttime
$runtime = $runtime.ToString()
$runtime1 = $runtime.split(".")
$totaltime = $runtime1[0]
Write-Output " " >> $logfile
Write-Output " " >> $logfile
Write-Output "|-------------------------------------------------------------------------------------- " >> $logfile
Write-Output "| SCRIPT COMPLETE : STATS " >> $logfile
Write-Output "|-------------------------------------------------------------------------------------- " >> $logfile
Write-Output "| Total Mailboxes Processed : $totalmailboxesprocessed " >> $logfile
Write-Output "| Total Additions : $totaladditionstomailboxes " >> $logfile
Write-Output "| Total Removals : $totalremovalsfrommailboxes " >> $logfile
Write-Output "| Total Mailboxes Skipped due to ACL : $totalmailboxesskipped " >> $logfile
Write-output "| Start time : $starttime ">> $logfile
Write-output "| End time : $endtime ">> $logfile
Write-Output "| **END OF RUN** - Elapsed time : $totaltime " >> $logfile
Write-Output "|---------------------------------------------------------------------------------------" >> $logfile
Write-Output " " >> $logfile -
Use Lion Server to set up security in Web Sharing
Can I use Lion Server to set up security in Web Sharing?
I want a password prompt to appear when someone comes to look at my Web Sharing files.
I have tried to do this manually in Snow Leopard and Lion, and am considering buying Lion Server just for this one purpose.
Does the admin GUI in Lion Server have an option that allows you to set up a password prompt for folks that look at my Web Sharing files?
THanks.
macMiracles do happen.
Because I just bought Lion Server, I was able to get a guy from the Apple Server support group on the phone, for a long time, and he helped me set this up using the Server app and the Server Admin app.
Now I have a password prompt on my Web Sharing files.
It's an incredible relief to have this working.
Thanks for the responses. -
Materialized Views created using ROLLUP
Not sure if this one is best posted to a general Oracle forum, or even to the Discoverer Forum, but it's more to do with Data Warehousing so here goes...
1. If I create a materialized view, either with or without OWB, do I also need to separately create indexes on the materialized view?
2. If I create them using GROUP BY and ROLLUP (to create summaries that calculate all the subtotals along all hierarchies and dimensions), would any subsequent query have to use GROUP BY and ROLLUP to qualify for query rewrite?
3. If I create them using GROUP BY and ROLLUP, would the queries generated by Discoverer ever get rewritten, as I assume they would not use GROUP BY and ROLLUP as these were not features found in earlier versions of Oracle?
Any advice gratefully received.
MarkThanks for replying, Igor.
Just to clarify:
1. Do MV's created without fash refresh capabilities still get indexes created automatically? If not, should you manually create them in this instance?
2. Can you confirm that, if a MV gets created using GROUP BY and ROLLUP (to potentially calculate all dimension intersections in one go), users queries to the base fact table do not have to use ROLLUP in their GROUP BY clause - they will still get rewritten ok?
3. You mentioned that Discoverer generates queries using GROUP BY - does it ever use GROUP BY ROLLUP if it knows it's working on an Oracle 9i platform?
I guess where i'm coming from, is that we're considering using the OLAP Summary Manager within OEM to create materialized views, rather than the normal summary adviser, as this creates MV's designed to hold (R)OLAP cubes (as detailed at http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574241). I wouldn't however want to use these if user's queries had to specify ROLLUP in their GROUP by clause to qualify for query rewrite.
Getting back to OWB, are there any plans to improve the support for importing, designing and refreshing materialized views in the Paris release of OWB? Summary management is perhaps a bit of a weak spot in OWB, and it'd be good if Hierarchical Cube Materialized Views - which are an excellent new feature in 9i - were supported in future releases.
best regards
Mark Rittman -
There is misleading information in two system views (sys.data_spaces & sys.destination_data_spaces) about the physical location of data after a partitioning MERGE and before an INDEX REBUILD operation on a partitioned table. In SQL Server 2012 SP1 CU6,
the script below (SQLCMD mode, set DataDrive & LogDrive variables for the runtime environment) will create a test database with file groups and files to support a partitioned table. The partition function and scheme spread the test data across
4 files groups, an empty partition, file group and file are maintained at the start and end of the range. A problem occurs after the SWITCH and MERGE RANGE operations, the views sys.data_spaces & sys.destination_data_spaces show the logical, not the physical,
location of data.
--=================================================================================
-- PartitionLabSetup_RangeRight.sql
-- 001. Create test database
-- 002. Add file groups and files
-- 003. Create partition function and schema
-- 004. Create and populate a test table
--=================================================================================
USE [master]
GO
-- 001 - Create Test Database
:SETVAR DataDrive "D:\SQL\Data\"
:SETVAR LogDrive "D:\SQL\Logs\"
:SETVAR DatabaseName "workspace"
:SETVAR TableName "TestTable"
-- Drop if exists and create Database
IF DATABASEPROPERTYEX(N'$(databasename)','Status') IS NOT NULL
BEGIN
ALTER DATABASE $(DatabaseName) SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE $(DatabaseName)
END
CREATE DATABASE $(DatabaseName)
ON
( NAME = $(DatabaseName)_data,
FILENAME = N'$(DataDrive)$(DatabaseName)_data.mdf',
SIZE = 10,
MAXSIZE = 500,
FILEGROWTH = 5 )
LOG ON
( NAME = $(DatabaseName)_log,
FILENAME = N'$(LogDrive)$(DatabaseName).ldf',
SIZE = 5MB,
MAXSIZE = 5000MB,
FILEGROWTH = 5MB ) ;
GO
-- 002. Add file groups and files
--:SETVAR DatabaseName "workspace"
--:SETVAR TableName "TestTable"
--:SETVAR DataDrive "D:\SQL\Data\"
--:SETVAR LogDrive "D:\SQL\Logs\"
DECLARE @nSQL NVARCHAR(2000) ;
DECLARE @x INT = 1;
WHILE @x <= 6
BEGIN
SELECT @nSQL =
'ALTER DATABASE $(DatabaseName)
ADD FILEGROUP $(TableName)_fg' + RTRIM(CAST(@x AS CHAR(5))) + ';
ALTER DATABASE $(DatabaseName)
ADD FILE
NAME= ''$(TableName)_f' + CAST(@x AS CHAR(5)) + ''',
FILENAME = ''$(DataDrive)\$(TableName)_f' + RTRIM(CAST(@x AS CHAR(5))) + '.ndf''
TO FILEGROUP $(TableName)_fg' + RTRIM(CAST(@x AS CHAR(5))) + ';'
EXEC sp_executeSQL @nSQL;
SET @x = @x + 1;
END
-- 003. Create partition function and schema
--:SETVAR TableName "TestTable"
--:SETVAR DatabaseName "workspace"
USE $(DatabaseName);
CREATE PARTITION FUNCTION $(TableName)_func (int)
AS RANGE RIGHT FOR VALUES
0,
15,
30,
45,
60
CREATE PARTITION SCHEME $(TableName)_scheme
AS
PARTITION $(TableName)_func
TO
$(TableName)_fg1,
$(TableName)_fg2,
$(TableName)_fg3,
$(TableName)_fg4,
$(TableName)_fg5,
$(TableName)_fg6
-- Create TestTable
--:SETVAR TableName "TestTable"
--:SETVAR BackupDrive "D:\SQL\Backups\"
--:SETVAR DatabaseName "workspace"
CREATE TABLE [dbo].$(TableName)(
[Partition_PK] [int] NOT NULL,
[GUID_PK] [uniqueidentifier] NOT NULL,
[CreateDate] [datetime] NULL,
[CreateServer] [nvarchar](50) NULL,
[RandomNbr] [int] NULL,
CONSTRAINT [PK_$(TableName)] PRIMARY KEY CLUSTERED
[Partition_PK] ASC,
[GUID_PK] ASC
) ON $(TableName)_scheme(Partition_PK)
) ON $(TableName)_scheme(Partition_PK)
ALTER TABLE [dbo].$(TableName) ADD CONSTRAINT [DF_$(TableName)_GUID_PK] DEFAULT (newid()) FOR [GUID_PK]
ALTER TABLE [dbo].$(TableName) ADD CONSTRAINT [DF_$(TableName)_CreateDate] DEFAULT (getdate()) FOR [CreateDate]
ALTER TABLE [dbo].$(TableName) ADD CONSTRAINT [DF_$(TableName)_CreateServer] DEFAULT (@@servername) FOR [CreateServer]
-- 004. Create and populate a test table
-- Load TestTable Data - Seconds 0-59 are used as the Partitoning Key
--:SETVAR TableName "TestTable"
SET NOCOUNT ON;
DECLARE @Now DATETIME = GETDATE()
WHILE @Now > DATEADD(minute,-1,GETDATE())
BEGIN
INSERT INTO [dbo].$(TableName)
([Partition_PK]
,[RandomNbr])
VALUES
DATEPART(second,GETDATE())
,ROUND((RAND() * 100),0)
END
-- Confirm table partitioning - http://lextonr.wordpress.com/tag/sys-destination_data_spaces/
SELECT
N'DatabaseName' = DB_NAME()
, N'SchemaName' = s.name
, N'TableName' = o.name
, N'IndexName' = i.name
, N'IndexType' = i.type_desc
, N'PartitionScheme' = ps.name
, N'DataSpaceName' = ds.name
, N'DataSpaceType' = ds.type_desc
, N'PartitionFunction' = pf.name
, N'PartitionNumber' = dds.destination_id
, N'BoundaryValue' = prv.value
, N'RightBoundary' = pf.boundary_value_on_right
, N'PartitionFileGroup' = ds2.name
, N'RowsOfData' = p.[rows]
FROM
sys.objects AS o
INNER JOIN sys.schemas AS s
ON o.[schema_id] = s.[schema_id]
INNER JOIN sys.partitions AS p
ON o.[object_id] = p.[object_id]
INNER JOIN sys.indexes AS i
ON p.[object_id] = i.[object_id]
AND p.index_id = i.index_id
INNER JOIN sys.data_spaces AS ds
ON i.data_space_id = ds.data_space_id
INNER JOIN sys.partition_schemes AS ps
ON ds.data_space_id = ps.data_space_id
INNER JOIN sys.partition_functions AS pf
ON ps.function_id = pf.function_id
LEFT OUTER JOIN sys.partition_range_values AS prv
ON pf.function_id = prv.function_id
AND p.partition_number = prv.boundary_id
LEFT OUTER JOIN sys.destination_data_spaces AS dds
ON ps.data_space_id = dds.partition_scheme_id
AND p.partition_number = dds.destination_id
LEFT OUTER JOIN sys.data_spaces AS ds2
ON dds.data_space_id = ds2.data_space_id
ORDER BY
DatabaseName
,SchemaName
,TableName
,IndexName
,PartitionNumber
--=================================================================================
-- SECTION 2 - SWITCH OUT
-- 001 - Create TestTableOut
-- 002 - Switch out partition in range 0-14
-- 003 - Merge range 0 -29
-- 001. TestTableOut
:SETVAR TableName "TestTable"
IF OBJECT_ID('dbo.$(TableName)Out') IS NOT NULL
DROP TABLE [dbo].[$(TableName)Out]
CREATE TABLE [dbo].[$(TableName)Out](
[Partition_PK] [int] NOT NULL,
[GUID_PK] [uniqueidentifier] NOT NULL,
[CreateDate] [datetime] NULL,
[CreateServer] [nvarchar](50) NULL,
[RandomNbr] [int] NULL,
CONSTRAINT [PK_$(TableName)Out] PRIMARY KEY CLUSTERED
[Partition_PK] ASC,
[GUID_PK] ASC
) ON $(TableName)_fg2;
GO
-- 002 - Switch out partition in range 0-14
--:SETVAR TableName "TestTable"
ALTER TABLE dbo.$(TableName)
SWITCH PARTITION 2 TO dbo.$(TableName)Out;
-- 003 - Merge range 0 - 29
--:SETVAR TableName "TestTable"
ALTER PARTITION FUNCTION $(TableName)_func()
MERGE RANGE (15);
-- Confirm table partitioning
-- Original source of this query - http://lextonr.wordpress.com/tag/sys-destination_data_spaces/
SELECT
N'DatabaseName' = DB_NAME()
, N'SchemaName' = s.name
, N'TableName' = o.name
, N'IndexName' = i.name
, N'IndexType' = i.type_desc
, N'PartitionScheme' = ps.name
, N'DataSpaceName' = ds.name
, N'DataSpaceType' = ds.type_desc
, N'PartitionFunction' = pf.name
, N'PartitionNumber' = dds.destination_id
, N'BoundaryValue' = prv.value
, N'RightBoundary' = pf.boundary_value_on_right
, N'PartitionFileGroup' = ds2.name
, N'RowsOfData' = p.[rows]
FROM
sys.objects AS o
INNER JOIN sys.schemas AS s
ON o.[schema_id] = s.[schema_id]
INNER JOIN sys.partitions AS p
ON o.[object_id] = p.[object_id]
INNER JOIN sys.indexes AS i
ON p.[object_id] = i.[object_id]
AND p.index_id = i.index_id
INNER JOIN sys.data_spaces AS ds
ON i.data_space_id = ds.data_space_id
INNER JOIN sys.partition_schemes AS ps
ON ds.data_space_id = ps.data_space_id
INNER JOIN sys.partition_functions AS pf
ON ps.function_id = pf.function_id
LEFT OUTER JOIN sys.partition_range_values AS prv
ON pf.function_id = prv.function_id
AND p.partition_number = prv.boundary_id
LEFT OUTER JOIN sys.destination_data_spaces AS dds
ON ps.data_space_id = dds.partition_scheme_id
AND p.partition_number = dds.destination_id
LEFT OUTER JOIN sys.data_spaces AS ds2
ON dds.data_space_id = ds2.data_space_id
ORDER BY
DatabaseName
,SchemaName
,TableName
,IndexName
,PartitionNumber
The table below shows the results of the ‘Confirm Table Partitioning’ query, before and after the MERGE.
The T-SQL code below illustrates the problem.
-- PartitionLab_RangeRight
USE workspace;
DROP TABLE dbo.TestTableOut;
USE master;
ALTER DATABASE workspace
REMOVE FILE TestTable_f3 ;
-- ERROR
--Msg 5042, Level 16, State 1, Line 1
--The file 'TestTable_f3 ' cannot be removed because it is not empty.
ALTER DATABASE workspace
REMOVE FILE TestTable_f2 ;
-- Works surprisingly!!
use workspace;
ALTER INDEX [PK_TestTable] ON [dbo].[TestTable] REBUILD PARTITION = 2;
--Msg 622, Level 16, State 3, Line 2
--The filegroup "TestTable_fg2" has no files assigned to it. Tables, indexes, text columns, ntext columns, and image columns cannot be populated on this filegroup until a file is added.
--The statement has been terminated.
If you run ALTER INDEX REBUILD before trying to remove files from File Group 3, it works. Rerun the database setup script then the code below.
-- RANGE RIGHT
-- Rerun PartitionLabSetup_RangeRight.sql before the code below
USE workspace;
DROP TABLE dbo.TestTableOut;
ALTER INDEX [PK_TestTable] ON [dbo].[TestTable] REBUILD PARTITION = 2;
USE master;
ALTER DATABASE workspace
REMOVE FILE TestTable_f3;
-- Works as expected!!
The file in File Group 2 appears to contain data but it can be dropped. Although the system views are reporting the data in File Group 2, it still physically resides in File Group 3 and isn’t moved until the index is rebuilt. The RANGE RIGHT function means
the left file group (File Group 2) is retained when splitting ranges.
RANGE LEFT would have retained the data in File Group 3 where it already resided, no INDEX REBUILD is necessary to effectively complete the MERGE operation. The script below implements the same partitioning strategy (data distribution between partitions)
on the test table but uses different boundary definitions and RANGE LEFT.
--=================================================================================
-- PartitionLabSetup_RangeLeft.sql
-- 001. Create test database
-- 002. Add file groups and files
-- 003. Create partition function and schema
-- 004. Create and populate a test table
--=================================================================================
USE [master]
GO
-- 001 - Create Test Database
:SETVAR DataDrive "D:\SQL\Data\"
:SETVAR LogDrive "D:\SQL\Logs\"
:SETVAR DatabaseName "workspace"
:SETVAR TableName "TestTable"
-- Drop if exists and create Database
IF DATABASEPROPERTYEX(N'$(databasename)','Status') IS NOT NULL
BEGIN
ALTER DATABASE $(DatabaseName) SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE $(DatabaseName)
END
CREATE DATABASE $(DatabaseName)
ON
( NAME = $(DatabaseName)_data,
FILENAME = N'$(DataDrive)$(DatabaseName)_data.mdf',
SIZE = 10,
MAXSIZE = 500,
FILEGROWTH = 5 )
LOG ON
( NAME = $(DatabaseName)_log,
FILENAME = N'$(LogDrive)$(DatabaseName).ldf',
SIZE = 5MB,
MAXSIZE = 5000MB,
FILEGROWTH = 5MB ) ;
GO
-- 002. Add file groups and files
--:SETVAR DatabaseName "workspace"
--:SETVAR TableName "TestTable"
--:SETVAR DataDrive "D:\SQL\Data\"
--:SETVAR LogDrive "D:\SQL\Logs\"
DECLARE @nSQL NVARCHAR(2000) ;
DECLARE @x INT = 1;
WHILE @x <= 6
BEGIN
SELECT @nSQL =
'ALTER DATABASE $(DatabaseName)
ADD FILEGROUP $(TableName)_fg' + RTRIM(CAST(@x AS CHAR(5))) + ';
ALTER DATABASE $(DatabaseName)
ADD FILE
NAME= ''$(TableName)_f' + CAST(@x AS CHAR(5)) + ''',
FILENAME = ''$(DataDrive)\$(TableName)_f' + RTRIM(CAST(@x AS CHAR(5))) + '.ndf''
TO FILEGROUP $(TableName)_fg' + RTRIM(CAST(@x AS CHAR(5))) + ';'
EXEC sp_executeSQL @nSQL;
SET @x = @x + 1;
END
-- 003. Create partition function and schema
--:SETVAR TableName "TestTable"
--:SETVAR DatabaseName "workspace"
USE $(DatabaseName);
CREATE PARTITION FUNCTION $(TableName)_func (int)
AS RANGE LEFT FOR VALUES
-1,
14,
29,
44,
59
CREATE PARTITION SCHEME $(TableName)_scheme
AS
PARTITION $(TableName)_func
TO
$(TableName)_fg1,
$(TableName)_fg2,
$(TableName)_fg3,
$(TableName)_fg4,
$(TableName)_fg5,
$(TableName)_fg6
-- Create TestTable
--:SETVAR TableName "TestTable"
--:SETVAR BackupDrive "D:\SQL\Backups\"
--:SETVAR DatabaseName "workspace"
CREATE TABLE [dbo].$(TableName)(
[Partition_PK] [int] NOT NULL,
[GUID_PK] [uniqueidentifier] NOT NULL,
[CreateDate] [datetime] NULL,
[CreateServer] [nvarchar](50) NULL,
[RandomNbr] [int] NULL,
CONSTRAINT [PK_$(TableName)] PRIMARY KEY CLUSTERED
[Partition_PK] ASC,
[GUID_PK] ASC
) ON $(TableName)_scheme(Partition_PK)
) ON $(TableName)_scheme(Partition_PK)
ALTER TABLE [dbo].$(TableName) ADD CONSTRAINT [DF_$(TableName)_GUID_PK] DEFAULT (newid()) FOR [GUID_PK]
ALTER TABLE [dbo].$(TableName) ADD CONSTRAINT [DF_$(TableName)_CreateDate] DEFAULT (getdate()) FOR [CreateDate]
ALTER TABLE [dbo].$(TableName) ADD CONSTRAINT [DF_$(TableName)_CreateServer] DEFAULT (@@servername) FOR [CreateServer]
-- 004. Create and populate a test table
-- Load TestTable Data - Seconds 0-59 are used as the Partitoning Key
--:SETVAR TableName "TestTable"
SET NOCOUNT ON;
DECLARE @Now DATETIME = GETDATE()
WHILE @Now > DATEADD(minute,-1,GETDATE())
BEGIN
INSERT INTO [dbo].$(TableName)
([Partition_PK]
,[RandomNbr])
VALUES
DATEPART(second,GETDATE())
,ROUND((RAND() * 100),0)
END
-- Confirm table partitioning - http://lextonr.wordpress.com/tag/sys-destination_data_spaces/
SELECT
N'DatabaseName' = DB_NAME()
, N'SchemaName' = s.name
, N'TableName' = o.name
, N'IndexName' = i.name
, N'IndexType' = i.type_desc
, N'PartitionScheme' = ps.name
, N'DataSpaceName' = ds.name
, N'DataSpaceType' = ds.type_desc
, N'PartitionFunction' = pf.name
, N'PartitionNumber' = dds.destination_id
, N'BoundaryValue' = prv.value
, N'RightBoundary' = pf.boundary_value_on_right
, N'PartitionFileGroup' = ds2.name
, N'RowsOfData' = p.[rows]
FROM
sys.objects AS o
INNER JOIN sys.schemas AS s
ON o.[schema_id] = s.[schema_id]
INNER JOIN sys.partitions AS p
ON o.[object_id] = p.[object_id]
INNER JOIN sys.indexes AS i
ON p.[object_id] = i.[object_id]
AND p.index_id = i.index_id
INNER JOIN sys.data_spaces AS ds
ON i.data_space_id = ds.data_space_id
INNER JOIN sys.partition_schemes AS ps
ON ds.data_space_id = ps.data_space_id
INNER JOIN sys.partition_functions AS pf
ON ps.function_id = pf.function_id
LEFT OUTER JOIN sys.partition_range_values AS prv
ON pf.function_id = prv.function_id
AND p.partition_number = prv.boundary_id
LEFT OUTER JOIN sys.destination_data_spaces AS dds
ON ps.data_space_id = dds.partition_scheme_id
AND p.partition_number = dds.destination_id
LEFT OUTER JOIN sys.data_spaces AS ds2
ON dds.data_space_id = ds2.data_space_id
ORDER BY
DatabaseName
,SchemaName
,TableName
,IndexName
,PartitionNumber
--=================================================================================
-- SECTION 2 - SWITCH OUT
-- 001 - Create TestTableOut
-- 002 - Switch out partition in range 0-14
-- 003 - Merge range 0 -29
-- 001. TestTableOut
:SETVAR TableName "TestTable"
IF OBJECT_ID('dbo.$(TableName)Out') IS NOT NULL
DROP TABLE [dbo].[$(TableName)Out]
CREATE TABLE [dbo].[$(TableName)Out](
[Partition_PK] [int] NOT NULL,
[GUID_PK] [uniqueidentifier] NOT NULL,
[CreateDate] [datetime] NULL,
[CreateServer] [nvarchar](50) NULL,
[RandomNbr] [int] NULL,
CONSTRAINT [PK_$(TableName)Out] PRIMARY KEY CLUSTERED
[Partition_PK] ASC,
[GUID_PK] ASC
) ON $(TableName)_fg2;
GO
-- 002 - Switch out partition in range 0-14
--:SETVAR TableName "TestTable"
ALTER TABLE dbo.$(TableName)
SWITCH PARTITION 2 TO dbo.$(TableName)Out;
-- 003 - Merge range 0 - 29
:SETVAR TableName "TestTable"
ALTER PARTITION FUNCTION $(TableName)_func()
MERGE RANGE (14);
-- Confirm table partitioning
-- Original source of this query - http://lextonr.wordpress.com/tag/sys-destination_data_spaces/
SELECT
N'DatabaseName' = DB_NAME()
, N'SchemaName' = s.name
, N'TableName' = o.name
, N'IndexName' = i.name
, N'IndexType' = i.type_desc
, N'PartitionScheme' = ps.name
, N'DataSpaceName' = ds.name
, N'DataSpaceType' = ds.type_desc
, N'PartitionFunction' = pf.name
, N'PartitionNumber' = dds.destination_id
, N'BoundaryValue' = prv.value
, N'RightBoundary' = pf.boundary_value_on_right
, N'PartitionFileGroup' = ds2.name
, N'RowsOfData' = p.[rows]
FROM
sys.objects AS o
INNER JOIN sys.schemas AS s
ON o.[schema_id] = s.[schema_id]
INNER JOIN sys.partitions AS p
ON o.[object_id] = p.[object_id]
INNER JOIN sys.indexes AS i
ON p.[object_id] = i.[object_id]
AND p.index_id = i.index_id
INNER JOIN sys.data_spaces AS ds
ON i.data_space_id = ds.data_space_id
INNER JOIN sys.partition_schemes AS ps
ON ds.data_space_id = ps.data_space_id
INNER JOIN sys.partition_functions AS pf
ON ps.function_id = pf.function_id
LEFT OUTER JOIN sys.partition_range_values AS prv
ON pf.function_id = prv.function_id
AND p.partition_number = prv.boundary_id
LEFT OUTER JOIN sys.destination_data_spaces AS dds
ON ps.data_space_id = dds.partition_scheme_id
AND p.partition_number = dds.destination_id
LEFT OUTER JOIN sys.data_spaces AS ds2
ON dds.data_space_id = ds2.data_space_id
ORDER BY
DatabaseName
,SchemaName
,TableName
,IndexName
,PartitionNumber
The table below shows the results of the ‘Confirm Table Partitioning’ query, before and after the MERGE.
The data in the File and File Group to be dropped (File Group 2) has already been switched out; File Group 3 contains the data so no index rebuild is needed to move data and complete the MERGE.
RANGE RIGHT would not be a problem in a ‘Sliding Window’ if the same file group is used for all partitions, when they are created and dropped it introduces a dependency on full index rebuilds. Larger tables are typically partitioned and a full index rebuild
might be an expensive operation. I’m not sure how a RANGE RIGHT partitioning strategy could be implemented, with an ascending partitioning key, using multiple file groups without having to move data. Using a single file group (multiple files) for all partitions
within a table would avoid physically moving data between file groups; no index rebuild would be necessary to complete a MERGE and system views would accurately reflect the physical location of data.
If a RANGE RIGHT partition function is used, the data is physically in the wrong file group after the MERGE assuming a typical ascending partitioning key, and the 'Data Spaces' system views might be misleading. Thanks to Manuj and Chris for a lot of help
investigating this.
NOTE 10/03/2014 - The solution
The solution is so easy it's embarrassing, I was using the wrong boundary points for the MERGE (both RANGE LEFT & RANGE RIGHT) to get rid of historic data.
-- Wrong Boundary Point Range Right
--ALTER PARTITION FUNCTION $(TableName)_func()
--MERGE RANGE (15);
-- Wrong Boundary Point Range Left
--ALTER PARTITION FUNCTION $(TableName)_func()
--MERGE RANGE (14);
-- Correct Boundary Pounts for MERGE
ALTER PARTITION FUNCTION $(TableName)_func()
MERGE RANGE (0); -- or -1 for RANGE LEFT
The empty, switched out partition (on File Group 2) is then MERGED with the empty partition maintained at the start of the range and no data movement is necessary. I retract the suggestion that a problem exists with RANGE RIGHT Sliding Windows using multiple
file groups and apologize :-)Hi Paul Brewer,
Thanks for your post and glad to hear that the issue is resolved. It is kind of you post a reply to share your solution. That way, other community members could benefit from your sharing.
Regards.
Sofiya Li
Sofiya Li
TechNet Community Support
Maybe you are looking for
-
Logging data after a trigger with Lookout Direct
Hi, I would like to log data with Lookout Direct after a trigger input (not periodically or continuously). I am using Lookout DIrect version 4.5.1 build 19 and a Direct Logic 250 PLC. Does anyone have suggestions on how to do this? I would prefer t
-
How to display Quantity fields in Table control
Hi, I need to display quantity fields in my table control based on the resb-meins field. i.e. I need a feature similar to qname of ALV Grid Control in Table control. Can any body help me. Regards, Srinivas
-
We have database 7.3.4 If we start very large proces (cursor with few milions rows) with inserting and commiting in the independent table the proces is very fast at beggining but after half of proces the speed of proces become slow-down (cca 5 times
-
Handle event of one report in other
Dear experts, I have a requirement wherein, if an action is done on the selection screen of one report, the event should be caught in an another report which is running in another session. Say if I click refresh button on selection screen of one repo
-
Preview goes to Homepage, not file
When I press preview, a new instance of the browser is opened up and it defaults to the home page, not the file I am editing and trying to preview. Any solutions?