How to find grand total
Hi experts,
I have one internal table containing 2 fields quantity and amount.In the output i want to show total quantity and total amount. How can i achive it..?
something like this
qty amt
1 10
2 20
3 30
6 60
reward guaranteed
thanks
Kaki
hi asit
iam not able to get the totals correctly....can u see this code....every thing is correct except grand totals..
REPORT YVFJAUD_BILLDET no standard page heading
line-size 200
line-count 65
message-id Z1.
*-- Table Declaration
TABLES: ZFJAUD_BILL,RLGRAP.
DATA: BEGIN OF T_BILL OCCURS 0,
VBELN LIKE ZFJAUD_BILL-VBELN, " Billin Doc number
POSNR like ZFJAUD_BILL-POSNR, " Billing item
CHARG like ZFJAUD_BILL-CHARG, " Batch Number
FKDAT like ZFJAUD_BILL-FKDAT, " Posting date
FKART like ZFJAUD_BILL-FKART, " Billing type
KUNAG like ZFJAUD_BILL-KUNAG, " Customer(Sold-to-party)
MATNR like ZFJAUD_BILL-matnr, " Material number
FKIMG like ZFJAUD_BILL-FKIMG, " Batch Quantity
NETWR like ZFJAUD_BILL-NETWR, " Amount
WAERK like ZFJAUD_BILL-WAERK, " Currency
VERPR like ZFJAUD_BILL-VERPR, " TP
BNAME like ZFJAUD_BILL-BNAME, " End customer
AUGRU_AUFT like ZFJAUD_BILL-AUGRU_AUFT, "Order reason
END OF T_BILL.
select-options : s_vtweg for ZFJAUD_BILL-vtweg obligatory,
s_vkbur for ZFJAUD_BILL-vkbur,
s_kunag for ZFJAUD_BILL-kunag,
s_matnr for ZFJAUD_BILL-matnr,
s_prodh for ZFJAUD_BILL-prodh,
s_erdat for ZFJAUD_BILL-erdat obligatory,
s_werks for ZFJAUD_BILL-werks,
s_lgort for ZFJAUD_BILL-lgort.
selection-screen begin of block blk1 with frame title text-002.
parameters : p_file like rlgrap-filename
default 'C:\yvfjaud_billdet.xls'.
SELECTION-SCREEN SKIP 1.
PARAMETERS : p_flag AS CHECKBOX DEFAULT ' '.
selection-screen end of block blk1.
START-OF-SELECTION.
perform collect_data.
perform display_data.
if p_flag = 'X'.
perform download_to_localpc.
endif.
TOP-OF-PAGE.
perform set_page_header.
*& Form collect_data
text
FORM collect_data .
SELECT VBELN POSNR CHARG FKART KUNAG MATNR FKDAT
FKIMG NETWR WAERK NETPR VERPR BNAME AUGRU_AUFT BNAME
FROM ZFJAUD_BILL
INTO CORRESPONDING FIELDS OF TABLE T_BILL
WHERE
vtweg IN s_vtweg AND
vkbur IN s_vkbur AND
kunag IN s_kunag AND
matnr IN s_matnr AND
prodh IN s_prodh AND
erdat IN s_erdat AND
werks IN s_werks AND
lgort IN s_lgort.
ENDFORM. "collect_data
FORM download_to_localpc .
call function 'WS_DOWNLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = t_bill.
if sy-subrc <> 0.
message E000 with 'Download not successful'.
endif.
ENDFORM. " download_to_localpc
FORM display_data .
sort t_bill by vbeln.
loop at t_bill.
if t_bill-AUGRU_AUFT = '100' OR
t_bill-AUGRU_AUFT = '101' OR
t_bill-AUGRU_AUFT = '102'.
t_bill-FKIMG = '0.00'.
endif.
write :/1 t_bill-VBELN ,
15 t_bill-POSNR,
25 t_bill-CHARG,
40 t_bill-FKDAT,
55 t_bill-FKART,
70 t_bill-KUNAG,
85 t_bill-matnr,
100 t_bill-FKIMG,
115 t_bill-NETWR,
140 t_bill-WAERK,
145 t_bill-VERPR,
165 t_bill-BNAME.
endloop.
data: line line like t_bill occurs 0 with header line.
loop at t_bill into line.
write:/ line-FKIMG,line-netwr.
AT END OF FKIMG.
SUM.
ULINE.
WRITE: / line-FKIMG, line-netwr.
SKIP.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: / line-FKIMG, line-netwr.
ENDAT.
endloop.
ENDFORM. " display_data
FORM set_page_header .
call function 'Z_REPORT_TITLE'
EXPORTING
line_size = sy-linsz
sy_title = 'Billing Details with Cost'
uline = 'X'
first_page_only = ' '.
write :1(15) 'Billing Doc' color col_heading,
15(15) 'Item' color col_heading,
25(15) 'Batch' color col_heading,
40(15) 'Posting Date' color col_heading,
55(15) 'Billing Type' color col_heading,
70(15) 'Sold-to-party' color col_heading,
85(30) 'Material' color col_heading,
110(15) 'Qty' color col_heading,
125(15) 'Amount' color col_heading,
140(15) 'Currency' color col_heading,
155(15) 'TP' color col_heading,
165(15) 'End Customer' color col_heading.
ENDFORM. " set_page_header
Similar Messages
-
How to get Grand Total Text in ALV GRID
Hi Folks,
I am able to get the SUBTOTAL TEXT .....But i need...
How to get Grand Total Text in ALV GRID Display...
Can any one give a Solution for this...Hi Surendar,
Check out this code.. this is showing Total Text in Toal line in the very first column.
REPORT zsales_ord_det_1 .
TABLES: ztable_10.
TYPE-POOLS: slis.
DATA: BEGIN OF it OCCURS 0,
srno(6) type c,
name LIKE ztable_10-name,
age LIKE ztable_10-age,
END OF it.
DATA : BEGIN OF it_temp OCCURS 0,
name LIKE ztable_10-name,
age LIKE ztable_10-age,
END OF it_temp.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
DATA: v_repid LIKE sy-repid,
i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
gs_layout TYPE slis_layout_alv,
gd_layout TYPE slis_layout_alv,
i_sort TYPE STANDARD TABLE OF slis_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv.
START-OF-SELECTION.
v_repid = sy-repid.
SELECT * FROM ztable_10 INTO TABLE it_temp.
LOOP AT it_temp .
it-srno = 'Total'.
it-name = it_temp-name.
it-age = it_temp-age.
APPEND it.
ENDLOOP.
END-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'IT'
I_STRUCTURE_NAME =
I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = i_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'SRNO'.
wa_fieldcat-tabname = it.
append wa_fieldcat to i_fieldcat.
LOOP AT i_fieldcat INTO wa_fieldcat.
IF wa_fieldcat-fieldname = 'AGE'.
wa_fieldcat-do_sum = 'X'.
MODIFY i_fieldcat FROM wa_fieldcat.
ENDIF.
IF wa_fieldcat-fieldname = 'SRNO'.
Hide this field so that it can display it's content i.e.
Total text in Subtotal level
wa_fieldcat-tech = 'X'.
wa_fieldcat-no_out = 'X'.
MODIFY i_fieldcat FROM wa_fieldcat TRANSPORTING tech no_out.
ENDIF.
ENDLOOP.
wa_sort-spos = 1.
wa_sort-fieldname = 'SRNO'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO i_sort.
gd_layout-no_totalline = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
i_callback_program = v_repid
I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
is_layout = gd_layout
it_fieldcat = i_fieldcat[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
it_sort = i_sort
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
I_HTML_HEIGHT_TOP =
I_HTML_HEIGHT_END =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it
EXCEPTIONS
program_error = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Regards,
Seema -
How to find out total of number of users accessing Hyperion Planning applications ?
Hi All,
Could someone help me with the details of how to find out total number of users who are accessing Hyperion Planning application in Env.?
This is with regard to licenses so wanted accurate and unique information,
Thanks
AmithHello Amith,
I think you should have a look at the blog of Cameron Lackpour http://camerons-blog-for-essbase-hackers.blogspot.be/
In the "Shared Services Stupid Trick" blogs, he shows how to find the real access to an application. The side benefit is that it is amusing to read.
In how far this is OK for the licenses is written on another page. You likely need to use the same method as Oracle does. Ask the Salesperson how to do this. (I am curious what his/her reply is).
Regards,
Philip Hulsebosch. -
How to find the total no of users in a client
Hi Techie's,
How to find the total no. of users in the client ? is it possible ?
i have tried out with the steps by viewing the table USR01,but i can't get the actual solution ?
solutions rewarded!
regards,
S.RajeshkumarHi rajesh,
You can use SU10, then click on "Authorization data" -> put * on user -> execute.. you should get a list of all users in the client with details included...
Also you can list them using USMM and check all licensed users....
Also SUIM -> users by complex selection criteria -> By user id -> put * on user -> execute.
Regards
Juan -
How to find the total no of pages in script
hi
how to find the total no of pages in scriptHi
· &SAPSCRIPT-FORMPAGES&:
This field contains a number representing the total number of pages of the currently formatted form (any output between START_FORM and END_FORM). The page counter mode (START, INC, HOLD) of the individual pages is ignored. You can use this symbol to formulate information like
Page x of y for your output.
· &SAPSCRIPT-JOBPAGES&:
This field contains a number representing the total number of pages of all forms contained in the currently formatted print request, in other words, of all forms created using the OPEN_FORM, START_FORM.. ENDFORM, START_FORM.. END_FORM,..., CLOSE_FORM function modules.
When using the SAPSCRIPT-FORMPAGES or SAPSCRIPT-JOBPAGES symbols, SAPscript leads all output pages of the current form or current print request into main memory to replace the symbol by the appropriate value. For large output jobs, this can mean a very large amount of memory.
· &PAGE&, &NEXTPAGE&
This symbols are initially converted using the options specified in the form of the page definition.
Reward all helpfull answers
Regards
Pavan -
OBIEE 11g - How to display Grand Total in graphs
hi ,
I am using obiee 11.1.1.6 version . In a report I have a requirement to display the grand total (present in the table) to be shown in the graph also . Kindly help.
Regards,
NivHi Niv,
One quick question here.How are you creating Grand Total?
I have created using grand total by row summing and inserting that value in the Group By Function.
Attached the screen shot for your reference.
GT - Download - 4shared
Mark if helps
Thanks, -
How to get grand total in query designer
Hi,
Antbody know how to get the grand total after the last row in query designer? I
ThanksHi,
If we select the very first Characterstic in the rows section and set the Supress result rows as "never".
That will show the overall result in the end of the report,
In the query properties tab ,check for display properties of the result.That should be set to bottom.
Hope this will work.
Thanks
Mukesh -
How to show grand total at bottom in Pivot view?
Hi All,
How to show the report Grand total at bottom in pivot table?Plz help.
Regards,
VaishnaviHi ,
Thanks for the reply but My report structure is like below:
AAA,BBB,CCC,DDD,EEE,FFF,GGG,HHH & III my report columns.I have arranged those columns in measure & i have to calculate the variance against each column like below structure.As per the report here I have lto calculate variance for 4 columns like AAA,BBB,CCC,DDD & after that total of each..then again variance for EEE,FFF & their total.After that i have to show grand total of all from AAAA to FFF likewise for rest of fields.
Measures variance
AAA(db column) 1
BBB(db column) 2
CCC(db column) 3
DDD(db column
Total 6
EEE(db column) 4
FFF(db column) 5
Total 9
Grand Total(AAA TO FFF) 15
GGG(db column) 6
Total 6
Grand Total(AAA TO GGG) 21
III(db column)
Grand Total(AAA TO III)
How to do that?
Regards,
Sonal
Edited by: Sonal on Jan 11, 2012 9:06 AM
Edited by: Sonal on Jan 11, 2012 9:15 AM
Edited by: Sonal on Jan 11, 2012 9:17 AM -
How to set Grand Total of a Measure when its aggregation rule is Max in Logical Layer
Hi
I have a Measure Column (Budget) and in Logical layer the aggregation rule is set as (Max) which looks like Max(Budget). But now it is included in the report and when my client is trying to see its grand total, it is giving the Max Budget figure of the report rather than giving the total sum(grand total).
Kindly share some ideas in achieving the grand total without disturbing the actual aggregation of the measure.Thank You for your reply.
In my case i don't have a problem with aggregation for Budget Measure(max(Fact_XXKC_SHIP_TO_BUDGET_CAT_F.SALESREP_BUDGET_YTD)). This is the aggregation rule applied on the Salesrep Budget YTD.
Now i created a report with columns
Salesrepresntative(Dimension),, Sales Invoices(Measure1),, SALESREP_BUDGET_YTD(Measure 2).
In the above report the values are perfect, but when we used Grand total option at ROW level in table view, the grand total of Measure1 is cumulative of all the rows, but the Grand total of SALESREP_BUDGET_YTD (measure2) is the max of all the columns.
What i require is the Grand total of SALESREP_BUDGET_YTD (measure 2) should be cumulative of all the columns.
I have shared my SQL query, kindly verify it and share any idea.
select sum(case when T97600.W_XACT_TYPE_CODE = 'Chargeback' then T93664.NET_AMT * T93664.GLOBAL1_EXCHANGE_RATE end ) as c1,
sum(case when T97600.W_XACT_TYPE_CODE = 'Credit Memo' then T93664.NET_AMT * T93664.GLOBAL1_EXCHANGE_RATE end ) as c2,
sum(case when T97600.W_XACT_TYPE_CODE = 'Debit Memo' then T93664.NET_AMT * T93664.GLOBAL1_EXCHANGE_RATE end ) as c3,
sum(case when T97600.W_XACT_TYPE_CODE = 'Standard Invoice' then T93664.NET_AMT * T93664.GLOBAL1_EXCHANGE_RATE when T97600.W_XACT_TYPE_CODE = 'Invoice Cancellation' then T93664.NET_AMT * -1 * T93664.GLOBAL1_EXCHANGE_RATE end ) as c4,
T315597.XXKC_RESOURCE_NAME as c5
from
W_CUSTOMER_LOC_USE_D T315597 /* Dim_W_CUSTOMER_LOC_USE_D_Status */ ,
W_SALES_INVOICE_LINE_F T93664 /* Fact_W_SALES_INVOICE_LINE_F */ ,
W_XACT_TYPE_D T97600 /* Dim_W_XACT_TYPE_D_Sales_Ivclns */
where ( T93664.XACT_TYPE_WID = T97600.ROW_WID and T93664.DELETE_FLG = 'N' and T93664.XX_SHIP_TO_LOC_USE_WID = T315597.ROW_WID )
group by T315597.XXKC_RESOURCE_NAME
) D1 full outer join (select max(T313184.SALESREP_BUDGET_YTD) as c1,
T315597.XXKC_RESOURCE_NAME as c2
from
W_CUSTOMER_LOC_USE_D T315597 /* Dim_W_CUSTOMER_LOC_USE_D_Status */ ,
XXKC_SHIP_TO_BUDGET_CAT_F T313184 /* Fact_XXKC_SHIP_TO_BUDGET_CAT_F */
where ( T313184.SITE_USE_WID = T315597.ROW_WID )
group by T315597.XXKC_RESOURCE_NAME -
How to display grand total only on the last page of my report
Hello
I need to display the grand total amount of the invoice only on the last page of every report. If the report has 1 page then the grand total will be displayed on the 1st page. If the report has 2 pages then a subtotal will be displayed on the 1st page adding up all the amounts on page 1 only, and the grand total will be displayed on the 2nd page, adding up all the amounts of page 1 and 2. If the report has 3 pages then the a subtotal will be displayed on page 1 adding up all the amounts of page 1, and another subtotal on page 2 adding up all the amounts of page 2, and the grand total are displayed on page 3 adding up the amounts of every page.
supplier amount
xx 100
yy 100
subtotal 200
page 1 of 2 --here i need to display only the total amounts of page 1
supplier amount
subtotal brought forward 200 --then i need to bring total of page 1 over to page 2
qq 300
zz 300
total 800 --here i have reached the end of the report and
need to display the grand total
page 2 of 2
--Currently i am displaying this on my report
supplier amount
xx 100
yy 100
total 800 --this one gives the problem cause it displays the grand total
---------- on page 1 of 2 even before you can see the amounts on the
next pages
page 1 of 2
supplier amount
qq 300
zz 300
total 800put the grand total in a frame and set it to print on the last page of the enclosing object.
-
Hi,
Experts,
I am able to get the subtotal text but i am not able to get the grand total text please pass some code or idea on it.
ex:
2510 gopi 10
2511 gopi 20
subtotal 30
2521 anand 20
2522 anand 10
2523 anand 50
subtotal 80
2512 vikram 30
subtotal 30
(blank----) 140.
Here i want to get text as 'COMPANY TOTAL'. by using REUSE_ALV_GRID_DISPLAY FM.
Thanks,
Shabeer ahmed.Hi,
you can get the 'COMPANY TOTAL' by using the following code:
LOOP AT i_main INTO w_main.* Storing the Total text need to be displayed in
ALV
w_final-total = 'COMPANY TOTAL'.
w_final-field1 = w_main-field1.
w_final-field2 = w_main-field2.
w_final-field3 = w_main-field3 .
APPEND w_final TO i_final. ENDLOOP.
Regards,
Santosh -
How to show Grand total values in Chart view....
Hi,
I have a crazy req. like i need to show grand totals values also on the chart view along with the normal metrics.
column Metric1 Metric2
AAA 10 20
BBB 30 15
CCC 20 15
TOTAL 60 50
so here i need the values 60 and 50 also also to be displayed in a line graph
cheersPretty simple to achieve :)
In your Pivot view, under Rows section where you have column dimensions like AAA,BBB etc...create a new calculated item say Grand Total with function as 'formula' and formula as sum(*). This will give you a new row with totals. Now Chart Pivoted Results and you are done.
Hope answered -
How to color Grand total column
Hi,
We got one requirement from our customer to show Grand Total column with RED color based on some condition.
Could you please let me know is it possible to make it color. we are using obiee 11.1.1.6.0
Thanks
AnirbanHi,
Thanks for your reply,
According to the link Below
http://gerardnico.com/wiki/dat/obiee/answer_xml,
We can able to change color for Grand total through XML, but the example is in 10g, there is nothing call saw:totalValues in 11g Currently, may be it is replaced with saw:displayGrandTotal, I tried that option also but it is not working.
Is there anything which we can do through xml, to achieve the above requirement?
Thanks
Anirban -
Dear friends,
I provide full details here ,my database table structure ,data and stored procedure and my problem ,
please review it and provide the solution or any idea to solve my problem.
I am working on a project in which members are added in a tree pattern, and get the payment accordingly.
below is my table structure ,data and stored procedure
CREATE TABLE Associate_Income
ID varchar(30) NOT NULL,
ParentID varchar(30) NULL,
IsLeft tinyint NULL,
IsRight tinyint NULL,
joingdate datetime NOT NULL
go
INSERT Associate_Income
(ID, ParentID, IsLeft, IsRight, joingdate)
SELECT 'Ramesh123', NULL, NULL, NULL '2014-01-03 16:31:15.000' UNION ALL
SELECT 'Sonu', 'Ramesh123', 1, NULL, '2014-01-03 16:45:21.000' UNION ALL
SELECT 'Pawan kumar', 'Ramesh123', NULL, 1, '2014-01-04 16:50:23.000' UNION ALL
SELECT 'Ravi123', 'Sonu', 1, NULL, '2014-01-04 17:03:22.000' UNION ALL
SELECT 'Vineet123', 'Sonu', NULL, 1, '2014-01-04 17:26:01.000' UNION ALL
SELECT 'dev123', 'Ravi123', 1, NULL, '2014-01-05 19:35:16.000' UNION ALL
SELECT 'Mukesh123', 'Ravi123', NULL, 1, '2014-01-05 19:40:41.000' UNION ALL
SELECT 'poonam123', 'Vineet123', 1, NULL, '2014-01-05 19:49:49.000' UNION ALL
SELECT 'monu', 'Pawan kumar', 1, NULL, '2014-01-05 17:32:58.000' UNION ALL
SELECT 'Arti123', 'Pawan kumar', NULL, 1, '2014-01-05 19:54:35.000' UNION ALL
My database table Associate_Income structure and data is as follow:
ID ParentID IsLeft IsRight joingdate
Ramesh123 NULL NULL NULL 2014-01-03 16:31:15.000
Sonu Ramesh123 1 NULL 2014-01-03 16:45:21.000
Pawan kumar Ramesh123 NULL 1 2014-01-04 16:50:23.000
Ravi123 Sonu 1 NULL 2014-01-04 17:03:22.000
Vineet123 Sonu NULL 1 2014-01-04 17:26:01.000
dev123 Ravi123 1 NULL 2014-01-05 19:35:16.000
Mukesh123 Ravi123 NULL 1 2014-01-05 19:40:41.000
poonam123 Vineet123 1 NULL 2014-01-05 19:49:49.000
monu Pawan kumar 1 NULL 2014-01-05 17:32:58.000
Arti123 Pawan kumar NULL 1 2014-01-05 19:54:35.000
by using below stored procedure i can count the total number of pairs under particular node in 2:1,1:1 ratio means first pair is completed when two node added to the left side of given parent node and one node added
right side of given parent node after that all pairs are completed when one node added left side and one node added right side of parent node (1:1 ratio)
example if i execute my stored procedure as follows it would return following.
EXEC count_pairs 'Ramesh123'
3
so there is 3 pairs as shown in my figure.
when we execute my stored procedure for ParentID 'sonu' it would return following.
EXEC count_pairs 'sonu'
2
so there is 2 pairs as shown in my figure.
My problem is to find the query which can return the total number of pair under particular node any given parent node. day to
day maximum 5 pairs in a day please any one can suggest us
CREATE proc [dbo].[count_pairs]
@ParentID nvarchar(50)
as
begin
Declare @ParentSUM SMALLINT = 0
Declare @SubLeftID nvarchar(50)
Declare @SubRightID nvarchar(50)
SELECT @SubLeftID = CASE WHEN [IsLeft] = 1 THEN [ID] ELSE @SubLeftID END
,@SubRightID = CASE WHEN [IsRight] = 1 THEN [ID] ELSE @SubRightID END
FROM Associate_Income
WHERE ParentID = @ParentID
IF @SubLeftID IS NOT NULL AND @SubRightID IS NOT NULL AND EXISTS(SELECT 1 FROM Associate_Income WHERE [IsLeft] = 1 AND ParentID = @SubLeftID)
BEGIN
SET @ParentSUM = 1
;WITH Associate_Income_CTE AS
SELECT [ID], [ParentID], [IsLeft], [IsRight], 0 AS [Level]
FROM Associate_Income
WHERE [ParentID] = @ParentID
UNION ALL
SELECT RecursiveMember.[ID], RecursiveMember.[ParentID], RecursiveMember.[IsLeft], RecursiveMember.[IsRight], Level + 1
FROM Associate_Income RecursiveMember
INNER JOIN Associate_Income_CTE AnchorMember
ON RecursiveMember.[ParentID] = AnchorMember.[ID]
SELECT @ParentSUM = @ParentSUM + COUNT([ParentID])
FROM
SELECT [ParentID]
,'IsLeft' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsLeft] = 1
AND [ID] <> @ParentID --AND [ID] NOT IN (@SubLeftID, @ParentID)
AND [ParentID] NOT IN (@ParentID, @SubLeftID)
UNION ALL
SELECT [ParentID]
,'IsRight' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsRight] = 1
AND [ParentID] <> @ParentID
) AS Associate_Income
PIVOT
MAX([Value]) FOR [Direction] IN ([IsLeft], [IsRight])
) PVT
WHERE [IsLeft] IS NOT NULL AND [IsRight] IS NOT NULL
END
SELECT @ParentSUM
Jitendra Kumar Sr. Software Developer at Ruvixo Technologies 7895253402I don't think this is homework, I am not sure how helpful it was by Kalman to merge the two threads. It appears that two different persons posted the questions. It could be though, that it is the same problem and Jitendra has taken over Chandra's
task.
However, I was not able to understand the problem nor the figure. And nor the definition of pairs in this context. My assumption is that what Jitendra posted is an abstraction of the actual problem in order to not reveal intellecutal property. Possibly this
makes the problem more difficult to understand for us outsiders.
I've come so far that I worked out a table definition and INSERT statements with sample data, as well as a call to the procedure which returns 3 and this appears to map to the figure, but I don't know what it means. Since I don't know what this
is about, I have not made any attepmts to understand the code, but I would appreciate clarification about the underlying business rules as well as the expected results for various test cases.
CREATE TABLE Associate_Income(ID varchar(30) NOT NULL,
ParentID varchar(30) NULL,
IsLeft tinyint NULL,
IsRight tinyint NULL,
joingdate datetime NOT NULL)
go
INSERT Associate_Income (ID, ParentID, IsLeft, IsRight, joingdate)
SELECT 'Ramesh123', NULL, NULL, NULL, '2014-01-03 16:31:15.000' UNION ALL
SELECT 'Sonu', 'Ramesh123', 1, NULL, '2014-01-03 16:45:21.000' UNION ALL
SELECT 'Pawan kumar', 'Ramesh123', NULL, 1, '2014-01-04 16:50:23.000' UNION ALL
SELECT 'Ravi123', 'Sonu', 1, NULL, '2014-01-04 17:03:22.000' UNION ALL
SELECT 'Vineet123', 'Sonu', NULL, 1, '2014-01-04 17:26:01.000' UNION ALL
SELECT 'dev123', 'Ravi123', 1, NULL, '2014-01-05 19:35:16.000' UNION ALL
SELECT 'Mukesh123', 'Ravi123', NULL, 1, '2014-01-05 19:40:41.000' UNION ALL
SELECT 'poonam123', 'Vineet123', 1, NULL, '2014-01-05 19:49:49.000' UNION ALL
SELECT 'monu', 'Pawan kumar', 1, NULL, '2014-01-05 17:32:58.000' UNION ALL
SELECT 'Arti123', 'Pawan kumar', NULL, 1, '2014-01-05 19:54:35.000'
go
CREATE proc [dbo].[count_pairs]
@ParentID nvarchar(50)
as
begin
Declare @ParentSUM SMALLINT = 0
Declare @SubLeftID nvarchar(50)
Declare @SubRightID nvarchar(50)
SELECT @SubLeftID = CASE WHEN [IsLeft] = 1 THEN [ID] ELSE @SubLeftID END
,@SubRightID = CASE WHEN [IsRight] = 1 THEN [ID] ELSE @SubRightID END
FROM Associate_Income
WHERE ParentID = @ParentID
IF @SubLeftID IS NOT NULL AND @SubRightID IS NOT NULL AND EXISTS(SELECT 1 FROM Associate_Income WHERE [IsLeft] = 1 AND ParentID = @SubLeftID)
BEGIN
SET @ParentSUM = 1
;WITH Associate_Income_CTE AS
SELECT [ID], [ParentID], [IsLeft], [IsRight], 0 AS [Level]
FROM Associate_Income
WHERE [ParentID] = @ParentID
UNION ALL
SELECT RecursiveMember.[ID], RecursiveMember.[ParentID], RecursiveMember.[IsLeft], RecursiveMember.[IsRight], Level + 1
FROM Associate_Income RecursiveMember
INNER JOIN Associate_Income_CTE AnchorMember
ON RecursiveMember.[ParentID] = AnchorMember.[ID]
SELECT @ParentSUM = @ParentSUM + COUNT([ParentID])
FROM
SELECT [ParentID]
,'IsLeft' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsLeft] = 1
AND [ID] <> @ParentID --AND [ID] NOT IN (@SubLeftID, @ParentID)
AND [ParentID] NOT IN (@ParentID, @SubLeftID)
UNION ALL
SELECT [ParentID]
,'IsRight' AS [Direction]
,1 AS [Value]
FROM Associate_Income
WHERE [IsRight] = 1
AND [ParentID] <> @ParentID
) AS Associate_Income
PIVOT
MAX([Value]) FOR [Direction] IN ([IsLeft], [IsRight])
) PVT
WHERE [IsLeft] IS NOT NULL AND [IsRight] IS NOT NULL
END
SELECT @ParentSUM
END
go
EXEC count_pairs 'Ramesh123'
go
DROP PROCEDURE count_pairs
DROP TABLE Associate_Income
Erland Sommarskog, SQL Server MVP, [email protected] -
How to find the total length of the string drawed in a rect?
Hello Everybody,
I am drawing a string in on one rect using drawInRect method. This drawInRect method gives us a return value as size of the rect. I need length of the string that is did draw in that rect, but didn't find any api to do this.
Can anyone tell me , how find the length of the string which we did draw in rect?
Any help regarding this issue , is highly appreciable.
Thanks,
PanditHi Adreas,
First of all, very thanks for the response.
Actually , I am looking for other thing. Using drawInRect method I am drawing contentString in self.rect like below.
//code
[contentString drawInRect:self.rect withFont:[UIFont fontWithName:@"Verdana" size:14.0] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
//End
My contentString is much larger string, so I am not able to draw it in rect(length: 320.0 height: 460.0) completely. My rect is showing only a part of a contentString. So I need to get that part of string which did draw in the rect, so that I can process my contentString to get the remaining string to draw it a next rect.
The above code statement is returning me the CGSIZE , it is giving the size of the rect but not giving any information of the string which get draw in that rect.Do you have any idea how to do this?
Any information on this is highly appreciable.
Thanks,
Pandit
Maybe you are looking for
-
Insert doc/pdf/jpg into BLOB using forms (web based)
Hi All, we have 81741 db on window2000(data server), forms6.0.8.20.1 on windows2000(webserver) & users using IE6/netscape as setup. User wants to store a pdf/doc/jpg file (stored on his PC) into database. He wants ability to view this pdf/doc/jpg lat
-
How to embed BARCODE into smartform ?
Hi All, I have a requirement to embed an EAN-128 barcode for handling unit(EXIDV) and other fields in a shipping label(smart form).please let me know how should I send the value for these · start code · FNC1 · application ident
-
HT204022 how to delete photos with ios 6
Ok so i just updated my Ipod touch 4g to IOS 6 and I didnt know that having iCloud would download all of my photos from my computer to iPod, and there is now 2500+ pictures on the ipod and i have no space for music, apps ext. How do i delete them for
-
WiSM Issue - More than three APs working at the power above threshold
According to the RRM document: http://www.cisco.com/en/US/tech/tk722/tk809/technologies_tech_note09186a008072c759.shtml , for each AP, the 3rd loudest AP should be heard at the power equal or lower than the threshold (default -65dbm or -70dbm accordi
-
Error using External Data Link
I just downloaded the trail of Visio Pro 2013 to test our the ability to reverse-enigineer my Data Warehouse db, running on postgres. After getting the ODBC connection configured and tested, I was given a list of the tables in the DB I connected to.