We help IT Professionals succeed at work.

SQL - Load records to temp table through CTE

csehz
csehz asked
on
105 Views
Last Modified: 2017-05-18
Dear Experts,

Could you please advise in this short question, is it possible to create table / load records to table through CTE?

Tried this simple code but that does not work in SQL:
USE DB;

IF OBJECT_ID (N'tempdb..#tCCs', N'U') is not null
DROP TABLE #tCCs
;

WITH 
	CCs AS (
		SELECT DISTINCT
			AP.LFB1.BUKRS
		INSERT INTO
			#tCCs
		FROM
			AP.LFB1)

SELECT 
	* 
FROM 
	#tCCs

Open in new window


Thanks in advance,
Comment
Watch Question

Vitor Montalv√£oIT Engineer
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Software Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
csehzIT consultant

Author

Commented:
Thanks for that
PortletPaulEE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013

Commented:
FYI

There is no need for a CTE, and no advantage by using a CTE, for your query. Why make it more complex than it needs to be?

USE DB;

IF OBJECT_ID (N'tempdb..#tCCs', N'U') is not null
DROP TABLE #tCCs
;

SELECT DISTINCT AP.LFB1.BUKRS
INTO #tCCs
FROM AP.LFB1

Open in new window

Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
>is it possible to create table / load records to table through CTE?
That does beg the question ... why are you asking??
csehzIT consultant

Author

Commented:
Asking that because having a complex query which is based on a lot of CTE's and came an idea that the result of one CTE should be placed to a temp table for later use by another query

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.