Questions Tagged With ivyhttps://answers.axonivy.com/tags/ivy/?type=rss&user=Hap%20Emquestions tagged <span class="tag">ivy</span>enFri, 01 Jul 2016 10:56:57 -0400Using local temporary tablehttps://answers.axonivy.com/questions/1856/using-local-temporary-table<p>Hello Every body!</p> <p>Look at the bellow picture, I have 2 database steps: 1. For the first step, it'll create a LOCAL temporary table and store the data in this table (For ex: It is named '#SUPERIOR') 2. The seconds step, it'll get data from '#SUPERIOR'</p> <p>But, we have some strange behaviors that sometimes it can not get data from '#SUPERIOR' temporary table. I guess that the '#SUPERIOR' is already dropped (because connection is closed --&gt; local temporary table is dropped) before step 2 is executed.</p> <p>Our application have a lot of users that can access concurrency (more than 1000 users)</p> <p>Could you pls give me some ideas?</p> <p>Thanks for your help!</p> <p><strong>This is sample of step1:</strong></p> <pre><code> Declare @ORSID int =1; DECLARE @EMPKEY int = 20018; DECLARE @CONNUMB varchar = '1'; DECLARE @SUPERIORORLID int = 1; DECLARE @PARENTID int = 0; IF OBJECT_ID('tempdb..#SUPERIORORGTREEANDROLE_eRAP20018') IS NOT NULL DROP TABLE #SUPERIORORGTREEANDROLE_eRAP20018 DECLARE @ORGTREEANDROLE TABLE( ORGID INT, ORGPNTOU INT, ORGCHDOU INT,ORSID INT, OUNDESC varchar(MAX), OUNTYPE varchar(MAX), ASNID INT, EMPKEY INT, CONNUMB varchar(MAX), ASNMAIN varchar(MAX), ORLID INT ); INSERT INTO @ORGTREEANDROLE SELECT org.ORGID, org.ORGPNTOU, org.ORGCHDOU, org.ORSID, ounc.OUNDESC, ounc.OUNTYPE, asnc.ASNID, asnc.EMPKEY, asnc.CONNUMB, asnc.ASNMAIN, asr.ORLID FROM HRMORG org LEFT OUTER JOIN HRMOUN ounc ON ounc.OUNKEY = org.ORGCHDOU LEFT OUTER JOIN HRMASN asnc ON asnc.OUNKEY = ounc.OUNKEY and asnc.ASNFROM &lt;= CONVERT(DATE, GETDATE()) and asnc.ASNUNTIL &gt;= CONVERT(DATE, GETDATE()) LEFT OUTER JOIN HRMASR asr ON asr.ASNID = asnc.ASNID WHERE org.ORSID = @ORSID and ounc.OUNFROM &lt;= CONVERT(DATE, GETDATE()) and ounc.OUNUNTIL &gt;= CONVERT(DATE, GETDATE()) ORDER BY org.ORGID SELECT @PARENTID = orgTree.ORGPNTOU FROM @ORGTREEANDROLE orgTree WHERE orgTree.CONNUMB = @CONNUMB AND orgTree.EMPKEY = @EMPKEY AND orgTree.ASNMAIN = 'Y' DECLARE @COUNT INT = 0; WHILE (@COUNT &lt; 20) BEGIN SET @COUNT = @COUNT + 1; IF (@PARENTID = 0 OR @PARENTID = NULL ) BEGIN BREAK; END ELSE BEGIN IF ((SELECT COUNT(ORGID)FROM @ORGTREEANDROLE orgTree WHERE orgTree.ORGCHDOU = @PARENTID AND orgTree.ORLID = @SUPERIORORLID) &gt; 0) BEGIN SELECT orgTree.EMPKEY, orgTree.CONNUMB, orgTree.ORGCHDOU ,orgTree.ASNID INTO #SUPERIORORGTREEANDROLE_eRAP20018 FROM @ORGTREEANDROLE orgTree WHERE orgTree.ORGCHDOU = @PARENTID AND orgTree.ORLID = @SUPERIORORLID BREAK; END END SELECT @PARENTID = orgTree.ORGPNTOU FROM @ORGTREEANDROLE orgTree WHERE orgTree.ORGCHDOU = @PARENTID END </code> </pre> <p>This is the sample for step2: </p><pre><code> SELECT * FROM #SUPERIORORGTREEANDROLE_eRAP20018; </code> </pre><p></p> <p><img alt="alt text" src="http://answers.axonivy.com/upfiles/process_getsuperior.png"></p> <p>Regards,</p>Hap EmFri, 01 Jul 2016 10:56:57 -0400https://answers.axonivy.com/questions/1856/using-local-temporary-tabledatabase_conversionivy