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 8457575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:50:34+00:00 2026-06-10T12:50:34+00:00

I know how to do this one way but the query i have created

  • 0

I know how to do this one way but the query i have created takes about 1:30 to run and i need to optimize this to be faster due to system limitations. Ive used multiple joins of the same table to do this but was wondering if there is a shorter query or more efficient query i could use.

Ive given a sample of the query but it does have about 100 columns pulled from a rows on the OrderItemFormDateFields table referenced below. Ive created columns and i get the results i need, but again, its slow. Let me know if you need any more detailed info about the tables.

I guess im basically looking for a way to dynamically populate rather than list out each column. Ive seen a few different ways with pivots and case statements but im not very good with pivots yet and case seemed like it would be even more inefficient. Thanks!

SELECT
OrderNumber
,Product
,OrderDate
,   oifd1.value as  'ADD_SUBJ_ADDRESS'
,   oifd2.value as  'ADD_SUBJ_BATHS'
,   oifd3.value as  'ADD_SUBJ_BEDROOMS'
,   oifd4.value as  'ADD_SUBJ_DATE'
,   oifd5.value as  'ADD_SUBJ_GLA'
FROM(
SELECT CAST(oi.orderid as VARCHAR(MAX))+'.'+CAST(oi.orderitemid as VARCHAR(MAX))     as      OrderNumber
,p.abbreviation as product, o.orderdate
FROM OrderItems oi
join products p on p.productid = oi.productid
join orders o on o.orderid = oi.orderid)x
left    join    orderitemformdatafields     oifd1   on      oifd1.orderreference    =   OrderNumber and oifd1.fieldname in  (     'SUBJ_STREET_ADDR')
left    join    orderitemformdatafields     oifd2   on      oifd2.orderreference    =   OrderNumber and oifd2.fieldname in  (      'ADD_SUBJ_BATHS')
 left   join    orderitemformdatafields     oifd3   on      oifd3.orderreference    =   OrderNumber and oifd3.fieldname in  (      'ADD_SUBJ_BEDROOMS')
 left   join    orderitemformdatafields     oifd4   on     oifd4.orderreference =   OrderNumber and oifd4.fieldname in  (     'ADD_SUBJ_DATE')
left    join    orderitemformdatafields     oifd5   on      oifd5.orderreference    =   OrderNumber and oifd5.fieldname in  (     'ADD_SUBJ_GLA')
  • 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-10T12:50:36+00:00Added an answer on June 10, 2026 at 12:50 pm

    hope this will help you.

    select * from (
    SELECT CAST(oi.orderid as VARCHAR(MAX))+'.'+CAST(oi.orderitemid as VARCHAR(MAX))     as      OrderNumber
    ,p.abbreviation as product, o.orderdate
    ,oifd.value as value
    ,oifd.fieldname as fieldname
    FROM OrderItems oi
    join products p on p.productid = oi.productid
    join orders o on o.orderid = oi.orderid
    left join orderitemformdatafields     oifd   on  oifd.orderreference = CAST(oi.orderid as VARCHAR(MAX))+'.'+CAST(oi.orderitemid as VARCHAR(MAX))
    ) as p
    PIVOT
    (
        MAX(value) FOR fieldname in ([SUBJ_STREET_ADDR],[ADD_SUBJ_BATHS],[ADD_SUBJ_BEDROOMS],[ADD_SUBJ_DATE],[ADD_SUBJ_GLA])
    )AS pvt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is largely an opinion, but I'm interested if you have one
I have a table with about 2,000,000 rows. I need to query one of
I know one way to solve this question is to Hash the words and
This is a very very basic question and I know one way is to
I know this one is the weirdest of all weird questions I have asked
This is one of those I probably should know this, but I don't questions.
This one goes round and round I know but I can't seem to find
I know there are questions similar to this one, but I've not found a
I think I already know the answer to this one, but i hope maybe
Is there a way to run code BEFORE model retrieval? I know about the

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.