473,394 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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_Revenue_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.fullname + ' '
+ costcenter.code from costcenter, agency_cost_center
where costcenter.oid = agency_cost_center.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_type_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_Revenue_tmp temp table
while (@pcount <= @ptcounter)
begin
Insert into @Recorded_Revenue_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_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

set @month = 1

--Loop that inserts values for the second part of the fiscal year into
the @Recorded_Revenue_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_Revenue_tmp temp table
while (@pcount <= @ptcounter)
begin
Insert into @Recorded_Revenue_tmp([Date], monthn, [Cost Center],[Payor
Type])
select 0,datename(month, @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_Revenue_tmp)

union

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

from chr_recorded_revenue a, chr_recorded_revenue_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.monthn, c.oid
thanks..Jim
Jul 20 '05 #1
1 2225
[posted and mailed, please reply in news]

Jim (ji********@motorola.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_tmp 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
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 =...
2
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 ...
0
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: ...
4
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...
15
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...
11
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...
4
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...
2
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...

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.