SQL Server WITH statement

0 votes

My objective is to use the same technique to select results from one CTE and insert them into another table using a different CTE. How do you do it?

Error:

invalid object name xy.

My query is:

WITH ds
(
    Select a, b, c 
    from test1    
),
xy
(
    select d, e, f 
    from test2 
    where (uses conditions from ds)    
)
Select * 
from ds  (the result set of ds, am exporting this to csv)

Insert into AuditTest
(
  Select * from xy
)

Can someone please help me with this?

Sep 8, 2022 in Database by Kithuzzz
• 38,010 points
490 views

1 answer to this question.

0 votes

I'm going to guess because I don't know the details of your database schema (columns, table name, etc.), so here is the 'generic' response:

SELECT COUNT(leads), COUNTY, STATE
FROM table
WHERE STATE = 'Texas'
GROUP BY COUNTY, STATE

I hope this helps you.

answered Sep 10, 2022 by narikkadan
• 63,700 points

Related Questions In Database

0 votes
0 answers

How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

In one ALTER TABLE statement, I would ...READ MORE

Sep 2, 2022 in Database by Kithuzzz
• 38,010 points
557 views
0 votes
1 answer

SQL Server CASE .. WHEN .. IN statement

Two forms of CASE statements are getting ...READ MORE

answered Feb 8, 2022 in Database by Vaani
• 7,060 points
548 views
0 votes
1 answer

What is "with (nolock)" in SQL Server?

Using READ UNCOMMITED as a transaction isolation ...READ MORE

answered Feb 21, 2022 in Database by Neha
• 9,060 points
465 views
0 votes
0 answers

What is "with (nolock)" in SQL Server?

Can someone explain the ramifications of using ...READ MORE

Feb 22, 2022 in Database by Vaani
• 7,060 points
535 views
0 votes
0 answers

SQL Server: Invalid Column Name

I am in the process of changing ...READ MORE

Aug 19, 2022 in Database by Kithuzzz
• 38,010 points
1,156 views
0 votes
0 answers

SQL Server Insert if not exists

I want to add data to my ...READ MORE

Aug 25, 2022 in Database by Kithuzzz
• 38,010 points
1,850 views
0 votes
1 answer

What does recursive stored procedure?

Recursive stored procedure refers to a stored ...READ MORE

answered Sep 27, 2018 in Database by Sahiti
• 6,370 points
14,815 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,060 points
865 views
0 votes
1 answer

INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server

Your table dbo.Sup Item Cat refers to ...READ MORE

answered Sep 19, 2022 in Database by narikkadan
• 63,700 points
7,658 views
0 votes
1 answer

How to calculate percentage with a SQL statement

The following has passed my tests, and ...READ MORE

answered Sep 12, 2022 in Database by narikkadan
• 63,700 points
5,165 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP