Greetings, Thanks a lot and as you said indeed no need to use the recursive common table expression within the code I shared and I already changed it and I used the CROSS APPLY operator and it works 100% fine and in 0 time instead of 24 seconds :) it was my fault what I wrote firstly :). However, I've been curious on knowing how the recursive common table expression works behind the scene :) as I said I know how it works in its simplest form but I wanted to know what if the anchor member will return more than one result that will be joined with the recursive member and so on... how things will be done. Thanks for help now I knew what I need :). Best regards, Amr Mohammad Rashad
Amr Mohammad87
Posts
-
Recursive Common Table Expressions -
Recursive Common Table ExpressionsGreetings, I am so grateful for your interesting in answering me :) thanks a lot. Recall I know how the recursive CTE works behind the scene in is simplest for when the anchor query will have a single result each time, for example, Employee A is the CEO, Employee B reports to Employee A, Employee C reports to Employee B, Employee D reports to Employee C, and Employee E reports to Employee D. So the chain of management will look like: B reports to A C reports to B D reports to C E reports to D But what if the management was looking like this: (A, B) -> (C, D, E) -> (F, G, H, I, J) where C, D report to A E report to B F reports to C G, H report to D I, J report to E So the first anchor member will return A and B those will be passed to the recursive member to get the C, D, and E etc. what I need to know is that is the mechanism of the recursion will go through A until it encounter NULL then go through B all way until it encounter NULL. I hope you got what I mean. 1- A, B 2- C, D 3- F 4- G, H 5- E 6- I, J Is that how it will go?!
-
Recursive Common Table ExpressionsWITH TradingReceivableAccounts (AccountID, AccountCode, AccountName, GeneralAccount, AccountBranch, NatureOfAccount, AccountType, DebtorValue, CreditorValue, [Entry], [Description]) AS
(SELECT at.Account_ID,
at.Account_Code,
at.Account_Name1,
at.Account_Isleaf,
aib.AccountBranch_BranchID,
aib.AccountBranch_Natural,
aib.AccountBranch_Type,
ISNULL(aib.AccountBranch_LocalDebit, 0) AS DebtorValue,
ISNULL(aib.AccountBranch_LocalCredit, 0) AS CreditorValue,
CAST(NULL AS NVARCHAR(250)) AS [Entry],
N'TradingReceivableAccounts' AS [Description]
FROM AccountTree AS at INNER JOIN Account_InBranch AS aib
ON at.Account_ID = aib.AccountBranch_AccountID
AND aib.AccountBranch_Natural = 1
AND aib.AccountBranch_Type = 2
AND aib.AccountBranch_BranchID = 1UNION ALL
SELECT ac.Account_ID,
ac.Account_Code,
ac.Account_Name1,
ac.Account_Isleaf,
CAST(0 AS INT) AS AccountBranch,
CAST(0 AS BIT) AS NatureOfAccount,
CAST(0 AS TINYINT) AS AccountType,
jd.JournalDet_Debit,
jd.JournalDet_Credit,
CAST(jh.Journal_Code AS NVARCHAR(250)),
N'TradingReceivableAccounts' AS [Description]
FROM TradingReceivableAccounts AS CTE INNER JOIN AccountTree AS ac
ON CTE.AccountID = ac.Account_ID
INNER JOIN Journal_Details AS jd
ON jd.JournalDet_AccountID = ac.Account_ID
INNER JOIN Journal_Head AS jh
ON jh.Journal_ID = jd.JournalDet_HeadID
AND jh.Journal_BranchID = CTE.AccountBranch
AND jh.Journal_Date < N'02/18/2016')The above query have the same idea. The anchor member returns a specific types of financial accounts and the recursive member gets all the payments\receipts transactions associated with each account. For example, lets say the anchor query returns the accounts 1, 2, 3, and 4 and with each account returned the recursive member will return all the payments\receipts associated with the account. I need to know how it will work behind the scene.
-
Recursive Common Table ExpressionsGreetings, I need to know how the recursive common table expression work behind the scene specifically when the recursive member returned with many result entries not a single result entry (i.e., single row) for example, the anchor member gets only one manager, and the first recursive member gets 3 employees follow that manager and they are, the 3 employees, in their turn are also managers to other employees etc. I hope that my question is clear
-
Web API needed or not?!I am already using HTML file api to read files from local system and those file(s) are simply photo(s) which the client will choose to use it to be displayed on the front-end banners(s). Now I need to send those photo(s) I've read to the server to be stored within a specific folder there and I do not know what I have to do for that even if I have a Web API (ASP.NET Web API) that accepts data sent to it then doing the storing functionality how can I send the data to those method(s) within the Web API I mean the jQuery get, post, and getJson methods need a URL for the Web API so do I have to write the IP address of the server (which I do not know in advance) in this URL or I can use something like this ./myapi/mycontroller to call the methods within my Web API?!!!
-
Web API needed or not?!I mean is there a way that enable javascript or jQuery to send something like a request to a specific server to store/retrieve data or I must do this through a Web API. Sorry I am new to web development
-
Web API needed or not?!Greetings, I am working on a website back end and I am using Bootstrap and jQuery to handle the pages layout and the user interaction. However, I need to make some read/writing at the server side (i.e., saving pictures that will be displayed on the front end and updating data within the database) my question is do I have to implement a Web API to handle such operation reading/writing to the server or there is a way for doing that through using jQuery or Javascript only?!
-
Database creation on an external HDGreetings, I have a database creation script. I've run the script after changed the path within the 'FILENAME' option to create the database on an external hard disk and I was able to see and select data from tables as the script run with no errors. However, when I tried to connect to the database from an application and read data from database tables, an exception thrown for SQL Server error 823 "The operating system returned error 21(The device is not ready.) to SQL Server during a read at offset 0x00000000132000 in file 'Database name'. Additional messages in the SQL Server error log and system event log may provide more detail. This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.". I've tried to run database consistency commands against it but they did not carried out and I got an error message. Also when I tried to drop or recover the database, dropping and recovering process failed. Finally, I had to make the database offline then I dropped it. I need to create such database on my external hard disk not on my primary one. Can anyone help?!!!
-
Database creation on external HDYeah sure I know. It is my fault I forgot to check in which forum I am posting my question. Sorry, I need now to remove the post from the C/C++ forum.
-
Database creation on external HDGreetings, I have a database creation script. I've run the script after changed the path within the 'FILENAME' option to create the database on an external hard disk and I was able to see and select data from tables as the script run with no errors. However, when I tried to connect to the database from an application and read data from database tables, an exception thrown for SQL Server error 823 "The operating system returned error 21(The device is not ready.) to SQL Server during a read at offset 0x00000000132000 in file 'Database name'. Additional messages in the SQL Server error log and system event log may provide more detail. This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.". I've tried to run database consistency commands against it but they did not carried out and I got an error message. Also when I tried to drop or recover the database, dropping and recovering process failed. Finally, I had to make the database offline then I dropped it. I need to create such database on my external hard disk not on my primary one. Can anyone help?!!!
-
binary treesThanks for your reply :) I just get confused a little bit as some books state that level start at 0 and others state that level starts at 1. We need a unified solution between those authors :)
-
binary treesI know it is correct to say 2^N, however, to say for level N+1 is what makes me confused because tree's level starts at level 0 which mean that N = 0 so if we apply the above statement it will be 2^0 for level 0 + 1 which means 1 node for level number 1 I hope you get what I meant.
-
binary treesI know it is correct to say 2^N, however, to say for level N+1 is what makes me confused because tree's level starts at level 0 which mean that N = 0 so if we apply the above statement it will be 2^0 for level 0 + 1 which means 1 node for level number 1 I hope you get what I meant
-
binary treesI read it in 2 books "Data Structures Through C in Depth" and "Data Structures and Algorithms in C++, 4th Edition" and even the link you gave to me saying "The root of the tree, therefore, is at level 0" which means that tree's level starts at 0. So I am confused because those books also saying that tree's level starts at 0?!!!
-
binary treesI've read the following statement and I cannot understand something within it "In all binary trees, there are at most 2^i nodes at level i + 1" what I cannot understand is that tree's levels start at level 0, however, if we apply what is written in this statement there will be no level 0 at all as it says level i + 1 which mean 0 + 1 = level 1, 1 + 1 = level 2, etc. So is this statement wrong?!!! or I am missing something?!!!
-
A Data Structures Book NeededYou are right about the copyright stuff. However, with complete respect to you and your opinion, not all people can get what they want especially if the thing related with payment(s) because they may have no money or it will cost them lots of money for me for example to buy this book for me will cost 2080 EGP so if for example, has a need for 10 books I will pay like 20800 EGP and that is lots of money for me + shipping fees, sorry for talking to much but I am trying to explain why I was asking for help from someone who may have it. Also I could have a book I do not need it or use it and a friend want it and was about buying and I give him mine so do you think it is violation in such situation?!!!. Wishing you good day :)
-
STL list member function(S)I read it in a book called "Data Structures and Algorithms in C++, 4th Edition by Adam Drozdek" it was in chapter 3 "Linked Lists" at the beginning of page 110 :). It made me had the feeling of this :wtf: :confused::~ when read it, and after searching and find nothing I become like this ;P;P;P (i.e., psycho). Thanks by the way for reply :)
-
STL list member function(S)void assign(size_type n, el const T& el = T()) This function is a member function of the STL list class and I do not understand the bolded part. I understand the const T& el is a reference to a constant parameter which means I cannot change the value/content of the passed argument + I understand that el = T() means a default parameter so if there is no argument passed in the calling function the el will use the no-argument constructor of the T() type OK. But what make me confused the el at the beginning before the const?!!! so if someone can fill the blank gaps for me I will be grateful :). Thanks in advance.
-
A Data Structures Book NeededYeah but I cannot buy it as it costs too much form me 1 Dollar = 8 EGP that is why I asked for it if someone had a soft-copy of it. :)
-
A Data Structures Book NeededGreetings, I am looking for this book 'Data Structures Through C in Depth by S. K. Srivastava, Deepali Srivastava' as a soft copy and I cannot find it if anyone have it as a soft copy if he can upload it for me I will be too much grateful for him. Best regards!.