I have these two temp tables that I'm using (they were actually written by a previous developer and I'm trying to adapt his code to be faster without using cursors, but that's beside the point) and I've run into a little problem that I can't figure out.
Here's some code:
CREATE TABLE #bc1 (
[ContractID] decimal
,[custid] int
,[PostDate] date
,[RouteID] varchar(50)
,[RouteCommission] money
,[ContractTotal] money
,[ContractTotal0] money
)
INSERT INTO #bc1 ( [ContractID], [custid], [PostDate], [RouteID], [RouteCommission] )
SELECT
t.[ContractID]
,t.[custid]
,t.[PostDate]
,t.[RouteID]
,t.[RouteCommission]
FROM
#tc1 t;
Now, as you can see it's pretty simple. There's a table #bc1
being created with five columns, and it gets all of the data from another table which has 7 columns. This is pretty much smack in the middle of the query (which is about four pages, which is why I didn't include it) and this is where it breaks. It tells me
Msg 207, Level 16, State 1, Line 178
Invalid column name 'custid'.
and it's driving me nuts. Incidentally, line 178 is the insert statement.
Any ideas?