473,586 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with a temp table

Jim
For some reason the compiler is telling me that I must declarethe
variable @costcenter_tmp on lines 74 and 98...but if i put a select
statement in ther (for testing) before the loop I get data back from
the temp table..

why is this happening to this temp table and no others?..heres my
code..its a little lengthy
--Fiscal Year
declare @year smallint
set @year = 2004

--Month number the Fiscal year starts and ends
declare @month smallint
set @month = 7

--Place holder for number of costcenters
declare @cccounter smallint

--loop counter for cost centers
declare @ccount smallint
set @ccount = 1

--Place holder for number of payor types
declare @ptcounter smallint

--loop counter for payor types
declare @pcount smallint
set @pcount = 1

--Temp table to store the blank values for all cost centers/payor
types for the fiscal year
declare @Recorded_Reven ue_tmp table
(
Revenue money default 0,
[Date] varchar(15),
monthn smallint,
[Cost Center] varchar(50),
[Payor Type] varchar(50)
)

--Temp table to store the values of the coster centers
declare @costcenter_tmp table
(
ccid int IDENTITY (1,1),
ccname varchar(50)
)

--Inserts cost centers and code into the @costcenter_tmp temp table
insert into @costcenter_tmp (ccname) select costcenter.full name + ' '
+ costcenter.code from costcenter, agency_cost_cen ter
where costcenter.oid = agency_cost_cen ter.cost_center _moniker

--Sets the @cccounter variable to the number of cost centers
select @cccounter = count(*) from @costcenter_tmp

--Temp table to store the values of the payor types
declare @payor_type_tmp table
(
ptid int identity (1,1),
ptname varchar(50)
)

--Inserts payor types into the @payor_type_tmp temp table
Insert into @payor_type_tmp (ptname)select fullname from payor_type
where payor_type.oid = payor.payor_typ e_moniker

--Sets the @ptcounter variable to the number of payor types
select @ptcounter = count(*) from @payor_type_tmp
--Loop that gets the first part of the fiscal year
While (@month <13)
begin
--Loop that gets the value of the cost center to insert
While (@ccount <= @cccounter)
begin
--Loop that inserts values for the first part of the fiscal year into
the @Recorded_Reven ue_tmp temp table
while (@pcount <= @ptcounter)
begin
Insert into @Recorded_Reven ue_tmp(Revenue, [Date], monthn, [Cost
Center],[Payor Type])
select 0, datename(month, @month)+ ' ' + @year -1, @month, [Cost
Center], [Payor Type]
from @costcenter_tmp ,@payor_type_tm p where @costcenter_tmp .ccid =
@ccount and
@payor_type_tmp .ptid = @pcount
set @pcount = @pcount + 1
end
set @pcount = 1
set @ccount = @ccount + 1
end
set @ccount = 1
set @month = @month + 1
end

set @month = 1

--Loop that inserts values for the second part of the fiscal year into
the @Recorded_Reven ue_tmp temp table
While (@month <7)
begin
--Loop that gets the value of the cost center to insert
While (@ccount <= @cccounter)
begin
--Loop that inserts values for the first part of the fiscal year into
the @Recorded_Reven ue_tmp temp table
while (@pcount <= @ptcounter)
begin
Insert into @Recorded_Reven ue_tmp([Date], monthn, [Cost Center],[Payor
Type])
select 0,datename(mont h, @month)+ ' ' + @year, @month, [Cost Center],
[Payor Type]
from @costcenter_tmp , @payor_type_tmp where @costcenter_tmp .ccid =
@ccount and
@payor_type_tmp .ptid = @pcount
set @pcount = @pcount + 1
end
set @pcount = 1
set @ccount = @ccount + 1
end
set @ccount = 1
set @month = @month + 1
end
--Pulls in all the data for the report
(select Revenue,[Date],[Cost Center],[Payor Type] from
@Recorded_Reven ue_tmp)

union

(select (revenue) as Revenue, (b.monthname + ' ' + Cast(b.yearn as
varchar(4))) as 'Date',
c.fullname + ' ' + c.code as 'Cost Center',d.fulln ame as 'Payor
Type'

from chr_recorded_re venue a, chr_recorded_re venue_dates b,
costcenter c, payor_type d

where a.date = b.day and a.[Cost Center]= c.oid and a.[Payor Type]
= d.oid)

order by d.fullname,b.mo nthn, c.oid
thanks..Jim
Jul 20 '05 #1
1 2238
[posted and mailed, please reply in news]

Jim (ji********@mot orola.com) writes:
For some reason the compiler is telling me that I must declarethe
variable @costcenter_tmp on lines 74 and 98...but if i put a select
statement in ther (for testing) before the loop I get data back from
the temp table..

why is this happening to this temp table and no others?..heres my
code..its a little lengthy
...
The problem is here:
from @costcenter_tmp ,@payor_type_tm p where @costcenter_tmp .ccid =

===============
You cannot use a table variable as a column prefix. Use an alias instead:

from @costcenter_tmp , ct @payor_type_tmp pt where ct.ccid =
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4514
by: Vitamin | last post by:
I have written a stored procedure which will paging the recordset, and return a range of record that i need, and i write a asp code to call it however, no any return after the set objRs = objCmd.Execute when i try to Response.write (objRs.recordcount) it said the recordset is close.... how can i solve this problem?? thx ...
2
2305
by: Savas Ates | last post by:
i have a stored below it uses create temp table and drop temp table... when more than one user request the same page it probably returns error.. how can i solve this problem **************************************************************************** ***************************************** CREATE PROCEDURE st_seconddegree @fromwhom...
0
1164
by: Rob Welch | last post by:
I am changing my church band scheduling system from Excel to Database. I have assigned a schedule table in MySQL database that will be my master schedule. It contains the following fields: SCHEDULE TABLE ----------------------------------------- eventid (refers to a field in my events table that contain dates and types of...
4
2632
by: Not Me | last post by:
Hi, I have a stored procedure, that works perfectly when run from the query analyser, however if I run it through access vba, (using exec) I get a runtime error 208: invalid object name '#tmpContact'. Any ideas why this happens? The temporary table #tmpContact is used in the procedure, but as I say, it all works fine from the analyser. ...
15
3609
by: Hemant Shah | last post by:
Folks, We have an SQL statement that was coded in an application many years ago (starting with DB V2 I think). When I upgraded to UDB 8.2, the optimizer does not use optimal path to access the data. It takes about 4 minutes to get the data. In previous versions it was instantaneous. What do I need to do to increase the performance?
11
477
by: bofh1234 | last post by:
Hello, I am having a problem with linked lists. My program is based on a client server model. The client sends some packets of data to the server. The server reads those packets and is supposed to store the data in a linked list. It looks like everything works except for the fact that the linked list only stores the last value sent and...
4
2918
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of text and I can't find the error on why it isn't working. Any help is greatly appreciated. Here is the form
2
1476
by: evablue | last post by:
Hello to all, I am quite new to sql and I don't understand why a query has a certain output.I apologise for the long post but I'd rather describe exactly what I am doing in, hoping that someone can spot the problem that I fail to. I have created and populated two tables in my database that look like: Table: binding_sites id ...
3
2665
by: angusfreefa | last post by:
Dear All, I am facing a problem of transferring data between 2 tables within the same database. I set up 2 tables. The first table is the permanent table (oos_table) for saving records. the other table is a temp table (oos_table_temp) for storing records which all data would be deleted after the data transferred to the permanent table. ...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.