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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:49:17+00:00 2026-06-08T13:49:17+00:00

Is there a way to pass a value to a derived table query? In

  • 0

Is there a way to pass a value to a derived table query?

In the derived table I want reference a value ([docSVsys].[sID]) from the outer query.

I get an error:

Msg 4104, Level 16, State 1, Line 7 The multi-part identifier
“docSVsys.sID” could not be bound.

Yes I know this query can be simplified to no loop.
Have a cursor that has to loop and trying to convert it so set.

select top 10 [docSVsys].[sID], [sI].[count]
from docSVsys 
join 
(
    select count(*) as [count]   
    from docSVenum1 as [sIt]
    where  [sIt].[sID] = [docSVsys].[sID] 
) as [sI] 
on  '1' = '1'
order by [docSVsys].[sID]

Cross apply seemed to do the trick.
And it is exactly 1/3 faster than the cursor version.
Real query using cross apply below.

SELECT [sO].[sID], [sI].[max], [sI].[avg], [sI].[stdev]
FROM docSVsys as [sO] with (nolock)
cross apply 
( 
    select [sO].[sID], max(list.match) as 'max', avg(list.match) as 'avg', stdev(list.match) as 'stdev'
    from
    (
        select #SampleSet.[sID], [match] = 200 * count(*) / CAST ( #SampleSetSummary.[count] + [sO].[textUniqueWordCount]  as numeric(8,0) ) 
        from #SampleSet with (nolock) 
        join FTSindexWordOnce as [match] with (nolock) -- this is current @sID
            on match.wordID  = #SampleSet.wordID
            and [match].[sID] = [sO].[sID]
        join #SampleSetSummary with (nolock)  -- to get the word count from the sample set
            on #SampleSetSummary.[sID] = #SampleSet.[sID] 
        group by #SampleSet.[sID], #SampleSetSummary.[count] 
    ) as list
    having max(list.match) > 60 
) as [sI]  
where [textUniqueWordCount] is not null and [textUniqueWordCount] > 4 and [sO].[sID] <= 10686
order by [sO].[sID]
  • 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-08T13:49:19+00:00Added an answer on June 8, 2026 at 1:49 pm

    You can do what you want with a CROSS APPLY rather than a JOIN:

    select top 10 [docSVsys].[sID], [sI].[count] 
    from docSVsys  
    cross apply 
    ( 
        select count(*) as [count]    
        from docSVenum1 as [sIt] 
        where  [sIt].[sID] = [docSVsys].[sID]  
    ) as [sI]  
    order by [docSVsys].[sID] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to pass object as arguments value in Resque-workers. I want
Is there a way pass values from other controls (e.g. selected value of dropdownlist,
Is there a way to conditionally pass a value into this statement? OUTER APPLY
Is there a way i can pass a value to a form from another
Is there a way to pass a null value to a parameter in C#?
Other than querystring, is there any other way to pass a value with the
I am wondering if there is any way to pass in a value when
Is there any way to pass a callback to java code, from C. And
Is there a way to pass OutArgument value of one activity to InArgument of
Is there any way to pass a table method instead of fieldid to addLink

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.