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

  • Home
  • SEARCH
  • 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 8619881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:26:50+00:00 2026-06-12T06:26:50+00:00

Is there an efficient or simple way to query this? for example to minimize

  • 0

Is there an efficient or simple way to query this? for example to minimize server load. Thanks!

db table

qId     WKDT    WK_ENDT                  SUM_LVL_Sort  ADOCD  ocd  OfficeName     WKLY_AVG  WeekCode
------  ------  -----------------------  ------------  -----  ---  -------------  --------  --------
201112  201110  2011-10-28 00:00:00.000  19.00         NULL   NAT  NATION         2.23      n
201112  201110  2011-10-28 00:00:00.000  13.00         NULL   F09  SAN FRANCISCO  2.20      n
201112  201111  2011-11-25 00:00:00.000  19.00         NULL   NAT  NATION         2.39      n
201112  201111  2011-11-25 00:00:00.000  13.00         NULL   F09  SAN FRANCISCO  2.14      n
201112  201112  2011-12-30 00:00:00.000  19.00         NULL   NAT  NATION         2.37      n
201112  201112  2011-12-30 00:00:00.000  13.00         NULL   F09  SAN FRANCISCO  2.18      n

This is the layout I need

WK_ENDT                  adocd  ocd  OfficeName     SUM_LVL_Sort  10    11    12
-----------------------  -----  ---  -------------  ------------  ----  ----  ----
2011-10-07 00:00:00.000  NULL   F09  SAN FRANCISCO  13.00         2.2   2.14  2.18
2011-10-07 00:00:00.000  NULL   NAT  NATION         19.00         2.23  2.39  2.37

tql query

 select TOP 1 (WK_ENDT),
     ,SUM_LVL_Sort
     ,ADOCD     as adocd
     ,Alias   as ocd
     ,OfficeName
     ,(select WKLY_AVG from kpi.dbo.tb_ssi_rzli where SUM_LVL_Sort = 19.00 and RIGHT(wkdt,2) = '10' and weekcode = 'n'  ) as [10]
     ,(select WKLY_AVG from kpi.dbo.tb_ssi_rzli where SUM_LVL_Sort = 19.00 and RIGHT(wkdt,2) = '11' and weekcode = 'n'  ) as [11]
     ,(select WKLY_AVG from kpi.dbo.tb_ssi_rzli where SUM_LVL_Sort = 19.00 and RIGHT(wkdt,2) = '12' and weekcode = 'n'  ) as [12]
from kpi.dbo.tb_ssi_rzli
where SUM_LVL_Sort = 19.00 and right(qId,2) = '12' and WeekCode = 'n'
order by WK_ENDT desc

bluefeet’s query result

WK_ENDT                  SUM_LVL_Sort  adocd  ocd  OfficeName  10    11    12
-----------------------  ------------  -----  ---  ----------  ----  ----  ----
2011-12-30 00:00:00.000  19.00         NULL   NAT  NATION      NULL  NULL  2.37
2011-11-25 00:00:00.000  19.00         NULL   NAT  NATION      NULL  2.39  NULL
2011-10-28 00:00:00.000  19.00         NULL   NAT  NATION      2.23  NULL  NULL
  • 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-12T06:26:51+00:00Added an answer on June 12, 2026 at 6:26 am

    Did you try this:

    select  (WK_ENDT),
         ,SUM_LVL_Sort
         ,ADOCD   as adocd
         ,Alias   as ocd
         ,OfficeName
         , CASE WHEN RIGHT(wkdt,2) = '10' THEN WKLY_AVG END As [10]
         , CASE WHEN RIGHT(wkdt,2) = '11' THEN WKLY_AVG END As [11]
         , CASE WHEN RIGHT(wkdt,2) = '12' THEN WKLY_AVG END As [12]
    from kpi.dbo.tb_ssi_rzli
    where SUM_LVL_Sort = 19.00 
        and right(qId,2) = '12'
        --and RIGHT(wkdt,2) IN ('10', '11', '12')
        and WeekCode = 'n'
    order by WK_ENDT desc 
    

    Edit try this, it looks like you want to get values based on the month:

    select TOP 1 (WK_ENDT),
    ,SUM_LVL_Sort
    ,ADOCD as adocd
    ,Alias as ocd
    ,OfficeName
    , CASE WHEN month(wkdt) = '10' THEN WKLY_AVG END As [10]
    , CASE WHEN month(wkdt) = '11' THEN WKLY_AVG END As [11]
    , CASE WHEN month(wkdt) = '12' THEN WKLY_AVG END As [12]
    from kpi.dbo.tb_ssi_rzli
    where SUM_LVL_Sort = 19.00
    and right(qId,2) = '12'
    and WeekCode = 'n'
    order by WK_ENDT desc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a built-in php function, or a simple (efficient!) way to combine built-in
There is a simple way to get top N rows from any table: SELECT
Is there an efficient way to version store procedures written in PL/SQL? (I only
Is there an efficient way to clone an object yet leave out specified properties?
Is there a more efficient way to list files from a bucket in Amazon
I have a simple question about the most efficient way to perform a particular
I'm trying to figure out the most efficient way to generate a WHERE query.
I have a simple MySQL query that looks something like this SELECT * FROM
I have a fairly simple one-to-many type join in a MySQL query. In this
I was wondering if there was a more efficient (efficient as in simpler/cleaner code)

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.