473,763 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB doesn't allow temp tables in Stored Procedures?

Using Visual Basic .NET and SQL Server 2005
I attempt to add a query that is a call to a stored procedure in the
DataSet Designer.

The TableAdapter Query Configuration wizard finds my stored procedure
fine but generates
the following error when I attempt to add the query

Invalid object name '#temp'.

I can tell from the Profiler that VB.NET makes a call to the stored
procedure with NULL values for all the parameters when it attempts to
create the calling function. I have no problem
if I call the procedure from SQL Server Management Studio. Does VB.NET
not allow
temporary tables in Stored Procedures???

Here is the code of the Stored Procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFI ER ON
go

-- =============== =============== ===============
-- =============== =============== ===============
ALTER PROCEDURE [dbo].[Set_Switch_Capa city]
-- Add the parameters for the stored procedure here
@ed_market_key varchar(25),
@month int,
@year int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

if @ed_market_key is NULL or @month is NULL or @year is NULL
return

create table #temp (
MSC_KEY varchar(25)
)

insert #temp
select MSC_KEY
from dbo.MSC_VIEW
where ed_market_key = @ed_market_key

-- Insert statements for procedure here
insert dbo.[Statistics]
select MSC_KEY,
@month as [month],
@year as [year],
2 as STAT_KEY,
Capacity
from dbo.Capacity
where not exists (select s.MSC_KEY as MSC_KEY
from dbo.[Statistics] s join #temp t
on s.MSC_KEY = t.MSC_KEY
where [month] = @month
and [year] = @year
and STAT_KEY = 2
)

END

Mar 7 '06 #1
2 2888
I'm not sure what your problem is, but the following comes to mind:

1. Try a different name than #temp. Perhaps it doesn't like that
name.
2. Try a table variable instead of a temp table. They use fewer
resources than a temp table and automatically go out of scope when the
proc ends.

Mar 8 '06 #2

Chris Dunaway wrote:
I'm not sure what your problem is, but the following comes to mind:

1. Try a different name than #temp. Perhaps it doesn't like that
name.
2. Try a table variable instead of a temp table. They use fewer
resources than a temp table and automatically go out of scope when the
proc ends.


Thanks Chris, creating a table variable did the trick. Now the question
is why?
Thanks again,

Crazy

Mar 8 '06 #3

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

Similar topics

2
3668
by: Tim Pascoe | last post by:
I'm relatively new to SQL-Server, and I have a quick question about temporary tables. I am using a function from Erland Sommarskog's excellent article about arrays in SQL server. Erland's approach uses a user-defined function, which parses a string of delimited values (integers) into a temporary table. The temporary table is joined to tables in a stored procedure select statement to limit the records returned. The question is, what...
4
2460
by: serge | last post by:
I tried all the INFORMATION_SCHEMA on SQL 2000 and I see that the system tables hold pretty much everything I am interested in: Objects names (columns, functions, stored procedures, ...) stored procedure statements in syscomments table. My questions are: If you script your whole database everything you end up having in the text sql scripts, are those also located in the system tables? That means i could simply read those system tables...
15
7260
by: brettclare | last post by:
I have linked a large SQL Server table to Access, however 'only' 2,195,439 records are shown and are available to query. Can I increase the size (cache??)/number of records showing in Access? Thank you.
1
1213
by: msnews.microsoft.com | last post by:
When you step into a stored procedure using vs.net, you get all the debug variables, except temp tables (like INSERT INTO #list (id) SELECT id FROM members WHERE...). Is it possible to view the temp tables? -Max
3
2700
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other words, a webpage may have to refer to 1 or more DataTables to populate itself. Therefore, a...
16
10330
by: pukivruki | last post by:
hi, I wish to create a temporary table who's name is dynamic based on the argument. ALTER PROCEDURE . @PID1 VARCHAR(50), @PID2 VARCHAR(50), @TICKET VARCHAR(20)
6
3300
by: betbubble | last post by:
I need help on two questions: 1. Is temp table the only way to pass recordsets from a nested stored procedure to a calling stored procedure? Can we avoid temp tables in this case? 2. Are operations in a stored procedure are treated as a transaction? Any help will be greatly appreciated. Background: We need to use temp table to pass recordsets from a nested stored procedure to a calling stored procedure. Our understanding is
7
15658
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
2
3178
by: kizmar | last post by:
You'll have to excuse me as I'm familiar with T-SQL (SQL Server), not so much DB2 when creating stored procedures... I'm trying to create a procedure where I build multiple temp tables (DECLARE GLOBAL TEMPORARY TABLE), insert data into each, then use those tables to insert data into a main temp table to be returned to a Crystal report. I can create the procedure when I declare the table and insert some records: CREATE PROCEDURE...
0
9564
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7368
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.