Stored procedure temporary table problem? - stored-procedures

I am using stored procedure to extract data from two different databases to a ASP.NET application. My stored procedure work as follows
- Check if global temporary table exist or not say ##temp_table
- if exist then drop it and if not create new temporary table say ##temp_table
- Extract data from two different databases and fill it to Temporary table
- Select data from temporary table
- Drop temporary table
Now problem is that when number of users accessing the same page with same stored procedure as above then to some users it get error that temporary table already exist.
Now please some one help me to solve such problem or suggest me some alternate because I don't want to write query in side ASP code. Some one suggest me to use views. Waiting for your suggestions.

"##" tables are accessible by all connections to the SQL instance, while "#" tables are accessible only by the connection that created them. The functionality you are describing sounds like you should be using "#" tables, not "##" tables.

You must not create table, you must declare variable for temporary table storage...with the column you expect to fill out...declare table variable like this:
declare #tmpTable table(myID int,myName varchar(50));
fill it like
insert into #tmpTable
Select * from table1
use it like
select * from #tmpTable

Related

Table schema changes sometimes

We use SQL Server and ADO in Delphi and we are creating temporary tables for use with a report program.
The program flow is like this :
Create a table with a SQL query "create table"
Write data in table.
Drop table via SQL query.
It usually works, but some customers regularly complain that "drop table" fails with error "invalid object name".
I could get remote access to the customers database, and I saw following :
the table X is shown in the table listing (by Delphi)
in Delphi, the table cannot be opened or deleted.
the table schema is "Server\1" instead of "dbo"!
How could the table schema of this table change, and how should I handle this issue? Why does it work sometimes, and sometimes not?
I would suggest using temporary tables and keeping all related code in SQL.
IF OBJECT_ID('tempdb..#YourTable') IS NOT NULL
DROP TABLE ##YourTable; -- just a precaution if it's already there
SELECT <field list>
into #YourTable -- this creates a the table with the structure of the "select" dataset
from YourSource_table
join Another_table on <join conditions>
where <your selection conditions>;
In a separate query read data from your temporary table
SELECT <field list> from #YourTable;
Make your report.
When all done, drop temporary table
IF OBJECT_ID('tempdb..#YourTable') IS NOT NULL
DROP TABLE ##YourTable;
Temporary tables accessible inside a single session; that means you must ensure you created it and read from the same connection component and keep it open in between. Other users won't see them (MS SQL server adds a unique suffix to its name)

Get the table name as dynamically in ssis

I have a table in that table i'm inserting all my TableNames of that database.
Now I need to pass this table name to OLEDB source DYNAMICALLY from my main table one by one
Is this possible to to pass the table name as dynamically in OLEDB source.
I suspect you are then going to run some SQL against the stored table name?
You'll need to approach this differently and run what you are trying within a SQL task.
If not, give us some more information about exactly what you are trying to achieve.

MVC - Select from Stored Procedure in Entity Framework

I am new to ASP.NET MVC. I should create a page where users enters an order for their shops by central warehouse. The products and amounts are listed by a stored procedure from database. I have to show rows in a gridview which are calculated by the stored procedure. I want to insert the changed data in a table in SQL after the user make changes on the gridview. Users can call the saved doc back and make changes on it and save it again.
I can't build a strategy how that can be made. If I use Entity Framework I can show the SQL table rows in grid but it is not my goal. I have to let the SQL calculate first the data. Could you please give me some start point and steps to go ahead. I hope I could explain what I need.
There Are some simple steps to do that
1- Go and update model from database and add the required Stored procedure
2- create a complex type from model browser
in complex type map your Stored procedure fields as it returns the data.
3- and map that complex type to the stored procedure. and use it as you use table.

How i can put a result set from a stored procedure in a temporary table in DB2

The title is very descriptive i think... My scenario is the next. I need to put the result of a result set (for example a result set with 6 columns and variable rows) from a stored procedure in some temporary table to make some operations over this new table.
I find some examples in the web but nothing in DB2...
The big problem is how to populate that new table with the restult set of a called stored procedure
DECLARE GLOBAL TEMPORARY TABLE probably accomplishes what you want. You can create this type of temporary table inside a stored procedure. It is visible only to the current session and is cleaned up for you when the session ends.

stored procedure to transfer data from a table in one database to a table in another database in oracle

there are 2 databases A AND B. i want to transfer data from a table in A TO a table in B. i want to use cursor for this. the duplicate datas when transferring should go to a table called duplicat table. I want a stored procedure to do the above. first i need to connect database A with database B using db link. i want the complete stored procedure. can anyone help plzzzzzzzzzz...........
Shouldn't you look for guidance rather then complete answer here, if you want to learn....
Google for how to create db link in oracle and how to use that in queries. Once this is done you just use the remote table as a normal table.
Following links are useful
http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/ds_admin002.htm
http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_5005.htm

Resources