Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cross Join in an Insert Into

Status
Not open for further replies.

BobThornton

Programmer
Sep 12, 2022
12
0
0
US
Please see the query below. When I run the Insert Into... by itself, it runs, but when I run the entire query it fails with - Column name or number of supplied values does not match table definition.
I'm trying to automate this query is why I have the T1 and T2. Thanks in advance for all of your help!
; WITH T1 AS (
SELECT *
FROM PPNO_DB.dbo.REF_CALENDAR
WHERE
YEAR = YEAR(GETDATE())
AND
MTH = MONTH(GETDATE())
AND DATE_DAY = 'Monday'
AND
RIGHT(DATE,2) BETWEEN '06' AND '13'
)

, T2 AS (
SELECT *,
CASE
WHEN CONVERT(DATE, GETDATE()) = T1.DATE
THEN 1
ELSE 0
END AS CHECK_DATE
FROM T1
)

--003_PNV_MMA_Networkdata Refresh Process
INSERT INTO AdHocData.MDCOutEd.PNV_MMA_NetworkData_Hist
SELECT *
FROM AdHocData.MDCOutEd.PNV_MMA_NetworkData_Curr
CROSS JOIN T2
WHERE T2.CHECK_DATE != '0'
 
My guess is that your query is returning one or more columns that are either in a different location or don't exist in your target table. Rather hard to tell without seeing the table structures.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top