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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:32:30+00:00 2026-05-16T22:32:30+00:00

I’m trying to use CROSS APPLY in SQL, but only want to use the

  • 0

I’m trying to use CROSS APPLY in SQL, but only want to use the results of the call if the returned row count is greater than 1.

I have the following SQL:

INSERT INTO    @dest (val1, val2, val3)
SELECT         t2.crossVal, t2.crossVal2, t1.tempVal
FROM        @tempTable t1
CROSS APPLY    dbo.TableValuedFunction(t1.IDColumn) t2

The CROSS APPLY returns multiple rows in some cases, but in the vast majority returns one row (as all @tempTable rows have a corresponding result from the function). I’m interesting in only inserting those that have multiple corresponding results from the CROSS APPLY.

I’m trying to avoid inserting all then doing a delete afterwards. Really interested to see if there is any sort of aggregation action I can apply to that statement as it is.

Any ideas?

Edit: in response to SQLMenace’s answer. I am getting the following results where the left column is tempVal, the middle column is crossVal, the right column is crossVal2:

a : 1 : z0

b : 1 : z0

a : 2 : z1

b : 2 : z1

c : 1 : z0

d : 1 : z0

I want to ditch the rows “c : 1 : z0” and “d : 1 : z0”. Also, it may affect the groupings so I will mention this, my final query has two columns returned from the function and one from the temp table.

The end query is basically counting the parents of the tempTable row, where there is more than one parent (returned as a table from the function) I want to do the insert and record the order of the parent (again returned from the function). crossVal is the parent ID and crossVal2 is the order as an int.

  • 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-05-16T22:32:31+00:00Added an answer on May 16, 2026 at 10:32 pm

    try this

    INSERT INTO    @dest (val1, val2)
    SELECT         t2.crossVal, t1.tempVal
    FROM           @tempTable t1
    CROSS APPLY    dbo.TableValuedFunction(t1.IDColumn) t2
    GROUP BY t2.crossVal, t1.tempVal
    HAVING COUNT(*) > 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.