Routine to count unique values
Hi Gurus,
I am BI user, I am trying to write a routine to populate count if employee and month from source fields is unique.
For example:
Employee calmonth count
10000 01.2008 1
10000 02.2008 1
10001 01.2008 1
10000 01.2008 0
Please can you help me with the code and any suggestions to write the code.
Regards,
Reddy.
Hi Eric,
Below is my code, count is always showing "0".
CLASS routine IMPLEMENTATION
CLASS lcl_transform IMPLEMENTATION.
METHOD compute_0HDCNT_LAST.
IMPORTING
request type rsrequest
datapackid type rsdatapid
SOURCE_FIELDS-PERSONAL_NO TYPE N LENGTH 000008
SOURCE_FIELDS-ZZMONTH TYPE C LENGTH 000007
EXPORTING
RESULT type tys_TG_1-HDCNT_LAST
DATA:
MONITOR_REC TYPE rsmonitor.
$$ begin of routine - insert your code only below this line -
TYPES:
BEGIN of ty_itab,
PERSONAL_NO(8) type n,
ZZMONTH(7) type c,
count(1) type c,
end of ty_itab.
data: itab type table of ty_itab.
field-symbols : <line> type ty_itab.
append SOURCE_FIELDS-PERSONAL_NO to itab.
append SOURCE_FIELDS-ZZMONTH to itab.
sort itab by PERSONAL_NO ZZMONTH.
loop at itab assigning <line>.
<line>-count = '0'.
AT NEW ZZMONTH.
<line>-count = '1'.
ENDAT.
endloop.
$$ end of routine - insert your code only before this line -
ENDMETHOD. "compute_0HDCNT_LAST
Method invert_0HDCNT_LAST
This subroutine needs to be implemented only for direct access
(for better performance) and for the Report/Report Interface
(drill through).
The inverse routine should transform a projection and
a selection for the target to a projection and a selection
for the source, respectively.
If the implementation remains empty all fields are filled and
all values are selected.
METHOD invert_0HDCNT_LAST.
$$ begin of inverse routine - insert your code only below this line-
... "insert your code here
$$ end of inverse routine - insert your code only before this line -
ENDMETHOD. "invert_0HDCNT_LAST
ENDCLASS. "routine IMPLEMENTATION
Similar Messages
-
How to count Unique Values in BEx
Hi Guys,
Can anybody please let me know how to count unique values of a characteristic.
Thanx in advance
PeterI have a similar scenario. If i drill up on the characterstic that had a count of one in each record, the total number of records should be stay equal to the summarised results in the last screen.
Would someone know how to do that .
Arti -
How to count unique values based on specific criteria
Hello,
I need to count the number of unique values in column A but only if the text in column I is a specific word - how do I do this?Let's say the values are in A1:A10 and they are numeric, and the text is in I1:I10.
As an array formula, confirmed with Ctrl+Shift+Enter:
=SUM(IF(I1:I10="word",1/COUNTIFS(A1:A10,A1:A10,I1:I10,"word")))
where "word" is the specific word you're looking for.
Regards, Hans Vogelaar (http://www.eileenslounge.com) -
How to get count of unique values of column B for each unique value of column A in Excel 2010?
I have an excel sheet containing 72,000 rows in Excel 2010, column A is "site name", column B is category. I want a result that shows number of sites for each category.
Column A Column B
site 1 Category 1
Site 1 Category 1
Site 2 Category 1
site 3 Category 2
site 3 Category 2
site 4 Category 2
site 5 Category 2
I want this result:
Category 1 2
Category 2 3
I tried some formula in a 3rd column and created a pivot table on that column, but it did not give me the result i want.
Any one has an idea ? what is the easiest way to achieve this?
Appreciate any pointerI tried both formula referenced in these two post (I think they are a little simpler than the one above):
http://stackoverflow.com/questions/11876238/simple-pivot-table-to-count-unique-values
http://stackoverflow.com/questions/18898138/pivot-table-count-unique-values-excel-2010
They both worked! and I got the result for my 72,000 rows!
Thanks for your help! -
How do I count the unique value pairs in two columns of a table?
I have a table (Table 2) that is populated with data from an imported .csv file. On table 1 I need to count the unique value pairs in two columns of Table 2.
Here's what I have:
Date Person
7/10/2011 A
7/12/2011 W
7/12/2011 X
7/12/2011 X
7/12/2011 X
7/12/2011 Z
7/14/2011 Z
7/15/2011 X
7/16/2011 Z
I'm focusing on person "X" and can easily count how many days that person shows up but what I want is to see on how many unique days that person shows up.
Here's the result I'm looking for (Person "X" shows up on 2 different days - 3 times on 7/12/2011 and once on 7/15/2011):
X 2
I can't seem to find a function that allows me to do that. I also am not allowed to modify Table 2 so that leaves me to come up with a solution on Table 1.
Any ideas would be greatly appreciated.Hi John,
Not being allowed to modify Table 2 is a minor inconvenience. Just copy (using a formula) the necessary two columns onto Table 1.
Yellow columns may be hidden. The procedure progresses from left to right. All formulas are entered into row 2 then filled down that column to the end of the table. The table must be as long as the list in column A of Table 2.
A2: =Table 2::A
Fill right to column B.
Fill both columns down as far as needed.
I've used actual Date and Time values in column A, formatted to show only the Date part, but the technique will work with text in these cells, provided all cells representing the same 'date' have exactly the same content.
C2: =A&B
This concatenates the contents of each row of columns A and B into a single text string.
D2: =COUNTIF($C$2:C2,C)
This counts the number of occurrences of the Date&Name string on the current row from the first regular cell in column C (C2) to the current cell.
E2: =IF(COUNTIF($B$2:B2,B)=1,MAX($E$1:E1)+1,"")
This constructs the index of first occurrences of each name, in the order they first occur. The index is used by LOOKUP in column F.
F2: =IF(ROW()-1>MAX(E),"",LOOKUP(ROW()-1,$E,$B))
This uses the index value created in E as a search-for value to extract a single copy of the names in column B. The result is a list of all distinct names in the list. Note that spelling differences will be counted as distinct names.The IF statement stops the listing when the last distinct name is extracted.
G2: =IF(LEN(F)>0,COUNTIFS($B,"="&F,$D,"=1"),"")
This counts the number of 'first occurrences of distinct Date & Name strings for each name on the list (ie. the number of distinct dates on which each name appears in the original list).
All of the functions used are described, with at least one example for each, in the iWork formulas and Functions User Guide. You can download the guide, and the Numbers '09 User Guide, via the Help menu in numbers.
Regards,
Barry -
Count of unique values in 7 columns
Hey there…
I have a Lookup table with 8 columns
ID = unique ID
U = Sunday,
M = Monday
T = Tues
W = Weds
R = Thur
F = Fri
S = Sat
Each of the ‘day’ columns can have a value between 1 and 1150, looks like this
ID U M T W R F S
1 15 15 16 15 17 345 17
What I am trying to find is a count of the deviation of each row… or how many of the days have different values
So for the above example
ID U M T W R F S COUNT
1 15 15 16 15 17 345 17 4
As there are 4 unique values in the week..
15,16,17,345
Any ideas on how that could be done in oracle? Stumped!Yep, pre-11g:
CREATE TABLE temp (id INTEGER, col_1 INTEGER, col_2 INTEGER, col_3 INTEGER, col_4 INTEGER, col_5 INTEGER, col_6 INTEGER, col_7 INTEGER);
INSERT INTO temp VALUES (1000, 1, 2, 3, 4, 5, 6, 7);
INSERT INTO temp VALUES (1001, 7, 2, 3, 4, 5, 6, 7);
INSERT INTO temp VALUES (1002, 1, 1, 1, 1, 1, 1, 1);
SELECT * FROM temp
ORDER BY id;
SELECT id, COUNT (DISTINCT col)
FROM (
SELECT id, col_1 col FROM temp UNION
SELECT id, col_2 FROM temp UNION
SELECT id, col_3 FROM temp UNION
SELECT id, col_4 FROM temp UNION
SELECT id, col_5 FROM temp UNION
SELECT id, col_6 FROM temp UNION
SELECT id, col_7 FROM temp
GROUP by id
ORDER BY 1;
Table dropped.
Table created.
1 row created.
1 row created.
1 row created.
ID COL_1 COL_2 COL_3 COL_4 COL_5 COL_6 COL_7
1000 1 2 3 4 5 6 7
1001 7 2 3 4 5 6 7
1002 1 1 1 1 1 1 1
ID COUNT(DISTINCTCOL)
1000 7
1001 6
1002 1 -
BEx query: count unique key figure values
Hi
I need a little help with a query. I need to count the number of unique key figure values. Se example;
Data:
Employee1 - 2
Employee2 - 3
Employee3 - 2
Employee4 - 1
Employee5 - 2
Employee6 - 1
Employee7 - 2
Wanted output:
1 - 2
2 - 4
3 - 1
What kind of options do I have?
Thanks
MikeI would create a new characterstic for the same key figure and placed in rows and count in columns.
and second approach would be , create condition with customer exit and write the logic to count the unique values.
This is just a direction to move forward with the assumption that you are good in using variables and wirting logic in ABAP.
Thanks,
Sukhi -
BEx query needs to count unique characteristic values
Is there any way to build a query using BEx query designer to count the number of unique values of a characteristic. For instance, my cube has detailed transactions for claim information. Each claim number can have multiple products. My query need to show the number of claims that exist for each product. I don't want the detail of the claim number, just how many claims exist.
Product Gross Paid Loss Claim Count
Total Auto $ 43,865.01 ?
Total Property $ 4,068,321.57 ?
Not assigned 19,426Hi,
Creat calculated keyfigure with data functions Count value and save with technical name.
Right click on that go to propertes, select count with exception aggregation - Claim Number,
also use after aggregation and decimal places '0'.
Regards
Malyadri -
How do you count the number of unique values?
I wanted to know how to create a function that will tell me how many unique values are in a list of values.
For example if I had this list:
15
15
12
12
12
2
1
I would get a result of 4. Because there are only 4 unique values 15, 12, 2, and 1.
I'm trying to create a spreadsheet that modeled the Sainte-Laguë method of voting; in case you're wondering. I'm using Numbers '09 if it matters.
ThanksThanks for the responses. That was fast.
I was hoping to fit it all in one cell, but I guess I could hide the columns used for calculation. I tried Badunit's Function and it works. However I found that if I have a column of all the same number it will return 0, when in fact it should return 1. Like if I had a column of 14s I should get one, because the number of different values that appears is 1. Also a minor note is that COUNTIF(B$2:B2,B2) should be COUNTIF(B2:B$2,B2), that makes sure that if you have anything below it doesn't interfere. At least that's what made it work for me.
Well I looked at the way you did your chart, Badunit, and it makes more sense than the way I was doing it. I was having to manually enter the number of seats every new row. I think it would have been easier to write a java program.
Anyways you guys have been helpful. Thanks again. -
Select Statement to Get Unique values in a Column
I am trying to figure out how to get all the unique values from a
table column?
select code from atable sort unique?
I am running 8.1.7
Does anyone know how to do this?
Thanks,Hi,
Here is the code for that.
Select empno from emp
group by empno
having count(empno) = 1
Regards,
Ganesh R -
Mapping Problem.. I Need to pass Unique value everytime to Target filed.
Hi All,
I need to pass some unique value everytime the message processed to the target field.
Source filed ---> Target Field
can anyone has the UDF to generate like this.. ?
I heard that through RFCLookup we can do that.. by maintaing some table and taking 2 parameters one as input and one as output and everytime when the message processes it will add by one to the previous value and pass to the target field.
I dont know much about these lookups..
Can anyone through some light on this, how i can solve this issue.??
Waiting for your answers.
Thanks&Regards
Deepthi.Hi Liang,
That's my exact issue.Please let me know when you find the solution.
Actually i tried with some UDF.. its generating unique values whenever mapping is executed.But when we Reboot the system we found that its reinitializing again from "1".
So definetly we need to maintain the count in some database and system has to update evytime according to that.
Iam trying something by calling RFC from UDF and updating the Ztable by incrementing everytime.
I wil let you know if i find any solution..
Meanwhile anyone wants to suggest me... Please respond.
Thanks
Deepthi. -
I want to update the unique values, if they are not inserted... Please help in this regard
CREATE OR REPLACE PROCEDURE PR IS
lv_operator VARCHAR2(1) := 'N';
TYPE subset_rt IS RECORD
ltt_whse_loc oe_sales_ord_commit.whse_loc%TYPE,
ltt_shape oe_sales_ord_commit.shape%TYPE,
ltt_isize oe_sales_ord_commit.isize%TYPE,
ltt_grade oe_sales_ord_commit.grade%TYPE,
ltt_length oe_sales_ord_commit.length%TYPE,
ltt_pieces NUMBER,
ltt_inv_lbs_commit oe_sales_ord_commit.inv_lbs_commit%TYPE,
ltt_roll_lbs_commit oe_sales_ord_commit.roll_lbs_commit%TYPE,
ltt_ishcom_lbs oe_sales_ord_commit.ishcom_lbs%TYPE);
TYPE subset_aat IS TABLE OF subset_rt
INDEX BY PLS_INTEGER;
aa_subset subset_aat;
errors NUMBER;
dml_errors EXCEPTION;
PRAGMA EXCEPTION_INIT(dml_errors, -24381);
BEGIN
lv_operator := sy_checkpriv(USER,
'SY_OPERATIONS');
SELECT whse_loc,
shape,
isize,
grade,
length,
0,
inv_lbs_commit,
roll_lbs_commit,
ishcom_lbs
BULK COLLECT INTO aa_subset
FROM oe_sales_ord_commit_temp
WHERE processed_datetime IS NULL
AND username = decode(lv_operator,
'Y',
username,
USER);
BEGIN
FORALL indx IN 1 .. aa_subset.COUNT SAVE EXCEPTIONS
INSERT INTO
(SELECT loc,
shape,
isize,
grade,
length,
pieces,
inv_lbs_commit,
roll_lbs_commit,
ishcom_lbs FROM oe_inventory_temp)
VALUES
aa_subset(indx);
EXCEPTION
WHEN OTHERS THEN
*+<<Trap the rows that have failed due to dup_val_on_index exception and update the inv_lbs_commit,+*
*+roll_lbs_commit, ishcom_lbs columns in oe_inventory_temp table>>+*
-- loc,shape, isize,grade, length, pieces are composite primary keys.
errors := SQL%BULK_EXCEPTIONS.COUNT;
DBMS_OUTPUT.PUT_LINE('Number of statements that failed: ' || errors);
FOR i IN 1..errors LOOP
DBMS_OUTPUT.PUT_LINE('Error #' || i || ' occurred during '||
'iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX);
DBMS_OUTPUT.PUT_LINE('Error message is ' ||
SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
DBMS_OUTPUT.PUT_LINE(aa_subset(SQL%BULK_EXCEPTIONS(i).ERROR_INDEX));
END LOOP;
END;
END PR;
/Due to the following restriction a number of simple collections is used instead of the collection of records.
[FORALL Statement|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/forall_statement.htm#sthref2742]: You cannot refer to individual record fields within DML statements called by a FORALL statement. Instead, you can specify the entire record with the SET ROW clause in an UPDATE statement, or the VALUES clause in an INSERT statement.
10g syntax of FORALL statement is used:
SQL> select * from a;
INT DT STR
1 10.02.2009 123
2 11.02.2009 567
SQL> desc a
Name Null? Type
INT NOT NULL NUMBER(38)
DT DATE
STR VARCHAR2(20)
SQL> select * from a;
INT DT STR
1 10.02.2009 123
2 11.02.2009 567
SQL> DECLARE
2 TYPE T_Int_List IS TABLE OF A.Int%TYPE INDEX BY PLS_INTEGER;
3 TYPE T_Dt_List IS TABLE OF A.Dt%TYPE INDEX BY PLS_INTEGER;
4 TYPE T_Str_List IS TABLE OF A.Str%TYPE INDEX BY PLS_INTEGER;
5
6 vInts T_Int_List;
7 vDts T_Dt_List;
8 vStrs T_Str_List;
9
10 eBulk_Error EXCEPTION;
11 PRAGMA EXCEPTION_INIT(eBulk_Error, -24381);
12 BEGIN
13 vInts(1) := 2;
14 vDts(1) := sysdate - 1;
15 vStrs(1) := '888';
16
17 vInts(2) := 3;
18 vDts(2) := sysdate - 22;
19 vStrs(2) := '0000';
20
21 BEGIN
22 FORALL indx IN INDICES OF vInts SAVE EXCEPTIONS
23 INSERT INTO A(Int, Dt, Str)
24 VALUES(vInts(indx), vDts(indx), vStrs(indx));
25 EXCEPTION
26 WHEN eBulk_Error THEN
27 DECLARE
28 vErr_Count INTEGER;
29 vErr_Message VARCHAR2(2000);
30 vErr_Indices T_Int_List;
31 BEGIN
32 vErr_Count := SQL%BULK_EXCEPTIONS.COUNT;
33 -- Getting the indices of rows with duplicate key
34 -- FOR vI IN 1 .. SQL%BULK_EXCEPTIONS.COUNT LOOP - Doesn't work for some reason on 10.2.0.1.0
35 FOR vI IN 1 .. vErr_Count LOOP
36 IF SQL%BULK_EXCEPTIONS(vI).Error_Code <> 1 THEN
37 -- Error other that duplicate key is reraised
38 vErr_Message := SQLERRM(-SQL%BULK_EXCEPTIONS(vI).Error_Code);
39 Raise_Application_Error(-20001, vErr_Message);
40 END IF;
41 vErr_Indices(SQL%BULK_EXCEPTIONS(vI).ERROR_INDEX) := SQL%BULK_EXCEPTIONS(vI).ERROR_INDEX;
42 END LOOP;
43
44 -- Bulk update
45 FORALL vI IN INDICES OF vErr_Indices
46 UPDATE A SET
47 Dt = vDts(vI),
48 Str = vStrs(vI)
49 WHERE Int = vInts(vI);
50 END;
51 END;
52 END;
53 /
PL/SQL procedure successfully completed.
SQL> select * from a;
INT DT STR
1 10.02.2009 123
2 09.02.2009 888
3 19.01.2009 0000Regards,
Dima
Edited by: DimaCit on Feb 10, 2009 10:39 AM -
Need to test if a column have unique values or not
Hi all,
in ETL process I need to check if some cols have unique values or not using sql or plsql.
Suppose we need to load a big file data with external table initially and then test if values
on one or more columns have unique values in order to proceed with ETL process.
What is the faster test I can execute to verify that a column have unique values or not?
It's better for the ETL performance, use:
a. techniques regard constraints like described on Ask tom forum
"ENABLE NOVALIDATE validating existing data"
(Ask Tom &quot;ENABLE NOVALIDATE validating existing da...&quot;)
b. "simply" query on the data?
like this:
select count(count(*)) distinct_count,
sum(count(*)) total_count,
sum(case when count(*) = 1 then 1 else null end) non_distinct_groups,
sum(case when count(*) > 1 then 1 else null end) distinct_groups
from hr.employees a
group by A.JOB_ID
c. use analytics function?
d. use some feature directly on external table?
Bye in advanceHere is the example to handling the errrs using LOG_ERRORS into concept. You will check this and let me know if any doubt you have
DATAFILE:-
1000,ANN,ZZ105
1001,KARTHI,ZZ106
1002,PRAVEEN,ZZ109
1002,PARTHA,ZZ107
1003,SATHYA,ZZ108
1000,ANN,ZZ105
----- Original Table With unique constraints
SQL> CREATE TABLE tab_uniqtest(student_id NUMBER(10) UNIQUE,
student_name VARCHAR2(15),
course_name VARCHAR2(15)
2 3 4
Table created.
----- External table
SQL> CREATE TABLE tab_extuniqtest(student_id NUMBER(10),
2 student_name VARCHAR2(15),
3 course_name VARCHAR2(15)
4 )
5 ORGANIZATION EXTERNAL
6 (
7 DEFAULT DIRECTORY ann_dir
8 ACCESS PARAMETERS
9 (
10 RECORDS DELIMITED BY NEWLINE
11 BADFILE 'tabextuniqtest_badfile.txt'
12 LOGFILE 'tabextuniqtest_logfile.txt'
13 FIELDS TERMINATED BY ','
14 MISSING FIELD VALUES ARE NULL
15 REJECT ROWS WITH ALL NULL FIELDS
16 (student_id,student_name,course_name)
17 )
18 LOCATION ('unique_check.csv')
19 )
20 REJECT LIMIT UNLIMITED;
Table created.
---- Error logging table to log the errors
SQL> CREATE TABLE dmlerrlog_uniqtest(ORA_ERR_NUMBER$ NUMBER ,
2 ORA_ERR_MESG$ VARCHAR2(2000),
3 ORA_ERR_ROWID$ ROWID,
4 ORA_ERR_OPTYP$ VARCHAR2(2),
5 ORA_ERR_TAG$ VARCHAR2(4000),
6 inserted_dt VARCHAR2(50) DEFAULT TO_CHAR(SYSDATE,'YYYY-MM-DD'),
7 student_id VARCHAR2(10)
8 );
Table created.
---- Procedure to insert from external table
SQL> CREATE OR REPLACE PROCEDURE proc_uniqtest
2 AS
3 v_errcnt NUMBER;
4 BEGIN
5 INSERT INTO tab_uniqtest
6 SELECT * FROM tab_extuniqtest
7 LOG ERRORS INTO dmlerrlog_uniqtest('PROC_UNIQTEST@TAB_UNIQTEST') REJECT LIMIT UNLIMITED;
8 SELECT COUNT(1) into v_errcnt
9 FROM dmlerrlog_uniqtest
10 WHERE ORA_ERR_TAG$ = 'PROC_UNIQTEST@TAB_UNIQTEST';
11 IF(v_errcnt > 0) THEN
12 ROLLBACK;
13 ELSE
14 COMMIT;
15 END IF;
16 DBMS_OUTPUT.PUT_LINE ( 'Procedure PROC_UNIQTEST is completed with ' || v_errcnt || ' errors') ;
17 EXCEPTION
18 WHEN OTHERS THEN
19 RAISE;
20 END proc_uniqtest;
21 /
Procedure created.
SQL> SET SERVEROUTPUT ON
SQL> EXEC proc_uniqtest;
Procedure PROC_UNIQTEST is completed with 2 errors
PL/SQL procedure successfully completed.
SQL> SELECT STUDENT_ID,ORA_ERR_MESG$ FROM dmlerrlog_uniqtest;
STUDENT_ID ORA_ERR_MESG$
1002 ORA-00001: unique constraint (
SCOTT.SYS_C0037530) violated
1000 ORA-00001: unique constraint (
SCOTT.SYS_C0037530) violated -
Counting Unique Records: very urgent
Hi,
I have to create a query for which i have to count the unique records appearing for a particular selection. For that i created a CK and in its agregation set Count all values <> 0 For customer. we are having Modality in my rows and CK in column. Now what happens if for 4 different records there is one customer then output appears one against that modality but it should show 4. As such there is no unique field in the cube that i can count. But we have maintined a Count key figure against each record in the cube that has value 1 for each row. But as it is a Key figure i cannot use it in aggregation. Is there any way to solve this situation....
Please help. Its very urgent..
Thanks
Points assured.Hello,
Use Exception Aggregation as Customer. It will work.
Crearte CKF
Assign 1 initial value
Count all properties
Exception aggretion is Customer.
I think It should work
Thanks,
Kishore
@KR -
Unable to Enforce Unique Values, Duplicate Values Exist
I have list in SP 2010, it contains roughly 1000 items. I would like to enforce unique values on the title field. I started by cleaning up the list, ensuring that all items already had a unique value. To help with this, I used the export
to excel action, then highlight duplicates within Excel. So as far as I can tell, there are no duplicates within that list column.
However, when I try to enable the option to Enforce Unique Values, I receive the error that duplicate values exist within the field and must be removed.
Steps I've taken so far to identify / resolve duplicate values:
- Multiple exports to Excel from an unfiltered list view, then using highlight duplicates feature > no duplicates found
- deleted ALL versions of every item from the list (except current), ensured they were completely removed by deleting from both site and site collection recycle bins
- Using the SP Powershell console, grabbed all list items and exported all of the "Title" type fields (Item object Title, LinkTitle, LinkTitleNoMenu, etc) to a csv and ran that through excel duplicate checking as well.
Unless there's some rediculous hidden field value that MS expects anyone capable of attempting to enforce unique values on a list (which is simple enough for anyone to figure out - if it doesn't throw an error), then I've exhausted anything I can think
of that might cause the list to report duplicate values for that field.
While I wait to see if someone else has an idea, I'm also going to see what happens if I wipe the Crawl Index and start it from scratch.
- JonFirst, I create index for a column in list settings, it works fine no matter duplicate value exists or not;
then I set enforce unique values in the field, after click OK, I get duplicate values error message.
With SQL Server profiler, I find the call to proc_CheckIfExistingFieldHasDuplicateValues and the parameters. After reviewing this stored procedure in content database,
I create the following script in SQL Server management studio:
declare @siteid
uniqueidentifier
declare @webid
uniqueidentifier
declare @listid
uniqueidentifier
declare @fieldid
uniqueidentifier
set @siteid='F7C40DC9-E5D3-42D7-BE60-09B94FD67BEF'
set @webid='17F02240-CE04-4487-B961-0482B30DDA84'
set @listid='B349AF8D-7238-419D-B6C4-D88194A57EA7'
set @fieldid='195A78AC-FC52-4212-A72B-D03144DC1E24'
SELECT
* FROM TVF_UserData_List(@ListId)
AS U1 INNER
MERGE JOIN
NameValuePair_Latin1_General_CI_AS
AS NVP1 WITH (INDEX=NameValuePair_Latin1_General_CI_AS_MatchUserData)
ON NVP1.ListId
= @ListId AND NVP1.ItemId
= U1.tp_Id
AND ((NVP1.Level
= 1 AND U1.tp_DraftOwnerId
IS NULL)
OR NVP1.Level
= 2)
AND NOT((DATALENGTH(ISNULL(NVP1.Value,
= 0)) AND U1.tp_Level
= NVP1.Level
AND U1.tp_IsCurrentVersion
= CONVERT(bit, 1)
AND U1.tp_CalculatedVersion
= 0 AND U1.tp_RowOrdinal
= 0 INNER
MERGE JOIN
NameValuePair_Latin1_General_CI_AS
AS NVP2 WITH (INDEX=NameValuePair_Latin1_General_CI_AS_CI)
ON NVP2.SiteId
= @SiteId AND NVP2.ListId
= @ListId AND NVP2.FieldId
= @FieldId AND NVP2.Value
= NVP1.Value
AND NVP2.ItemId <> NVP1.ItemId
CROSS APPLY TVF_UserData_ListItemLevelRow(NVP2.ListId, NVP2.ItemId,
NVP2.Level, 0)
AS U2 WHERE ((NVP2.Level
= 1 AND U2.tp_DraftOwnerId
IS NULL)
OR NVP2.Level
= 2)
AND NOT((DATALENGTH(ISNULL(NVP2.Value,
= 0))
I can find the duplicate list items based on the result returned by the query above.
Note that you need to change the parameter values accordingly, and change the name of NameValuePair_Latin1_General1_CI_AS table based on the last parameter of the
proc_CheckIfExistingFieldHasDuplicateValues stored procedure. You can review the code of this stored procedure by yourself.
Note that direct operation on the content database in production environment is not supported, please do all these in test environment.
Maybe you are looking for
-
How to migrate .wid reports from BO6.5 to XIR2?
Post Author: jasontai CA Forum: Migration to XI R2 We are planning the migration from BO6.5 to XIR2, but I haven't found any content about the migration of WEB Inteligence reports(.wid files), so would you give some suggestion or guidance on it? Than
-
APD collecting information form a BEX report from other system
Hi experts! Just wondering if it is possible to collect information from a BEX query from other system. And if possible, we wonder if you could kindly assis how to do it. Thank you very much in advance!!
-
Why is time capsule not doing a full system backup?
It's only backing my users folder and nothing more. Their is nothing excluded from time machine in the options. Also I have my time capsule set up the right way.
-
HT1933 My iPhone keeps deleting my notes on its own!
My iPhone keeps deleting my notes on its own.
-
Apple TV not working with airplay
So i am a bit of an apple freak, I have a macbook pro (2011) iPhone 5 & a iPad 2 and none if it will connect to my Apple TV Basically I am wanting to be able to run with airplay because its super hand for meetings etc, it was working fine then one da