Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:34:42+00:00 2026-06-09T23:34:42+00:00

I am using the below query for a company whose financial year starts from

  • 0

I am using the below query for a company whose financial year starts from August each year.

How do I order the query so that it orders from Period 08.2009, 09.2009... until the last row 07.2009 for any year (Aug-July)?

The results are derived from a SAP Business One database where Period column is nvarchar. (Microsoft SQL Server 2008).

Query:

SELECT T0.Name AS Period, 
       SUM(T2.LineTotal) AS CurrentDebtors, 
       MAX(T1.DocRate) AS ExchangeRate,
       SUM(CASE WHEN DATEDIFF(day, T1.DocDate, T1.DocDueDate) > 30
                THEN T2.LineTotal 
           END) AS NonCurrentDebtors, 
       T3.TurnoverMonth
  FROM OFPR T0 
 INNER JOIN OINV T1
    ON T0.AbsEntry = T1.FinncPriod 
 INNER JOIN INV1 T2 
    ON T1.DocEntry = T2.DocEntry
 INNER JOIN 
 (
    SELECT ORCT.FinncPriod, 
           SUM(ORCT.DocTotal) AS TurnoverMonth
      FROM ORCT
     WHERE YEAR(ORCT.DocDate) = '2009'
     GROUP BY ORCT.FinncPriod
 )  T3 
    ON T0.AbsEntry = T3.FinncPriod
 WHERE YEAR(T1.DocDate) = '2009'
 GROUP BY T0.Name, T3.TurnoverMonth
 ORDER BY T0.Name

Results:

Period   CurrentDebtors    ExchangeRate  NonCurrentDebtors  TurnoverMonth
01.2009   82221785.530000   68.420000     11365437.180000   105030603.650000
02.2009  103432923.420000   68.420000     14444391.890000    84554821.480000
03.2009  118881620.200000   68.420000     16292534.760000   105662045.900000
04.2009  115400360.770000   68.420000     28278615.950000   127528038.680000
05.2009  120497298.090000   68.420000     21524834.230000    94912946.080000
06.2009  124426393.780000   68.420000     31814427.220000    92526329.440000
07.2009  107881741.630000   68.420000     25339512.290000   125756922.560000
08.2009  147938452.250000   68.420000     35773934.510000   102350989.510000
09.2009  137295113.320000  126.500000     30572992.390000   141742820.230000
10.2009  134955455.780000   68.420000     34060549.000000    88356896.710000
11.2009  151664995.160000   68.420000     35388019.370000   112424543.000000
12.2009  169973243.880000   68.420000     47526181.370000   165130664.260000
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:34:43+00:00Added an answer on June 9, 2026 at 11:34 pm

    try this:

    Amusing your T0.Name is a character filed

    Your Order By Clause to replace with the code below

    order by
     case when cast(left (T0.Name,2) as int)>=8 
          then cast(left (T0.Name,2) as int)-8
          else cast(left (T0.Name,2) as int)+4 
     end  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using below mentioned query with about 400,000 records in each table its taking
I'm using Sql-Server, and I have the below query which returns all columns that
I'm using the below query to return results from a table using Full-Text-Search. In
I am using below CAML query but when I run,it returns all data from
I m using below query from c# to compare current date with date stored
im joining and retrieving values from two tables using the below query. It displays
i am using below query to update my all records but it starts update
I have this below query that I execute using java PreparedStatement: String dml=insert into
Am using the query below to search for products that contain a term in
I'm using below query to count the daily result, but now I'm make it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.