{"id":12152,"date":"2024-04-10T14:14:02","date_gmt":"2024-04-10T13:14:02","guid":{"rendered":"https:\/\/sdna.lu\/?p=12152"},"modified":"2024-04-10T14:29:47","modified_gmt":"2024-04-10T13:29:47","slug":"query-balance-on-all-accounts","status":"publish","type":"post","link":"https:\/\/sdna.lu\/?p=12152","title":{"rendered":"Query: Balance on all accounts"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>DECLARE @GLAccountSearchStr varchar(30);<br>DECLARE @Date date;<br>Set @GLAccountSearchStr = '513';<br>Set @Date = '31\/12\/2023';<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Select [LogicalName], [Number], [Currency], [ResMaxDate], Sum(Round([CyResult], 2)) as [CyResult] from<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>(<br>Select [Licence].[DeMaSy].[DBList].[LogicalName], [GLAccount].[Number], [Country].[Currency], '00:00:00' as [ResMaxDate], Sum([GLAccountCur].[CyAmount]) as [CyResult]<br>from ((([GLAccountCur]<br>INNER JOIN [GLAccount]<br>ON ([GLAccountCur].[GLAccountId] = [GLAccount].[Id] and [GLAccountCur].[DBId] = [GLAccount].[DBId]))<br>INNER JOIN [Country]<br>ON ([GLAccountCur].[CurrencyId] = [Country].[Id] and [Country].[DBId] = 0))<br>INNER JOIN [Licence].[DeMaSy].[DBList]<br>ON ([GLAccountCur].[DBId] = [Licence].[DeMaSy].[DBList].[DBId]))<br>where [GLAccount].[Number] like @GLAccountSearchStr + '%'<br>Group by [Licence].[DeMaSy].[DBList].[LogicalName], [GLAccount].[Number], [Country].[Currency]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Union All<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Select [Licence].[DeMaSy].[DBList].[LogicalName], [GLAccount].[Number], [Country].[Currency], Max([GLMovement].[Date]) as [ResMaxDate], Sum(Case When [GLMovement].[CD] = 'D' Then [GLMovement].[CyAmount] Else -[GLMovement].[CyAmount] End) as [CyResult]<br>from ((([GLMovement]<br>INNER JOIN [GLAccount]<br>ON ([GLMovement].[GLAccountId] = [GLAccount].[Id] and [GLMovement].[DBId] = [GLAccount].[DBId]))<br>INNER JOIN [Country]<br>ON ([GLMovement].[CurrencyId] = [Country].[Id] and [Country].[DBId] = 0))<br>INNER JOIN [Licence].[DeMaSy].[DBList]<br>ON ([GLMovement].[DBId] = [Licence].[DeMaSy].[DBList].[DBId]))<br>where [GLAccount].[Number] like @GLAccountSearchStr + '%'<br>and [GLMovement].[Date] &lt; @Date<br>Group by [Licence].[DeMaSy].[DBList].[LogicalName], [GLAccount].[Number], [Country].[Currency]<br>) as [ResTable]<br>Group by [LogicalName], [Number], [Currency], [ResMaxDate]<br>having Not Sum(Round([CyResult], 2)) = 0<br>and Year([ResMaxDate]) = 2023<br>order by [LogicalName], [Number], [Currency]<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DECLARE @GLAccountSearchStr varchar(30);DECLARE @Date date;Set @GLAccountSearchStr = &#8216;513&#8217;;Set @Date = &#8217;31\/12\/2023&#8242;; Select [LogicalName], [Number], [Currency], [ResMaxDate], Sum(Round([CyResult], 2)) as [CyResult] from (Select [Licence].[DeMaSy].[DBList].[LogicalName], [GLAccount].[Number], [Country].[Currency], &#8217;00:00:00&#8242; as [ResMaxDate], Sum([GLAccountCur].[CyAmount]) as [CyResult]from ((([GLAccountCur]INNER JOIN [GLAccount]ON ([GLAccountCur].[GLAccountId] = [GLAccount].[Id] and [GLAccountCur].[DBId] = [GLAccount].[DBId]))INNER JOIN [Country]ON ([GLAccountCur].[CurrencyId] = [Country].[Id] and [Country].[DBId] = 0))INNER JOIN [Licence].[DeMaSy].[DBList]ON ([GLAccountCur].[DBId] = [Licence].[DeMaSy].[DBList].[DBId]))where [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12152","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/sdna.lu\/index.php?rest_route=\/wp\/v2\/posts\/12152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdna.lu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdna.lu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdna.lu\/index.php?rest_route=\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/sdna.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12152"}],"version-history":[{"count":5,"href":"https:\/\/sdna.lu\/index.php?rest_route=\/wp\/v2\/posts\/12152\/revisions"}],"predecessor-version":[{"id":12162,"href":"https:\/\/sdna.lu\/index.php?rest_route=\/wp\/v2\/posts\/12152\/revisions\/12162"}],"wp:attachment":[{"href":"https:\/\/sdna.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdna.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdna.lu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}