Showing posts with label temp. Show all posts
Showing posts with label temp. Show all posts

Monday, February 20, 2012

No Temp tables in SQLDatasource???

Please tell me there's something I haven't set. I've done several tests now. If your final return in a stored proc is from a temp table (ala #mytable ) the system cannot read the schema - for that matter, it won't run at all, complaining that the object #mytable doesn't exists.

It can't possible be that temp tables aren't allowed in procs used by SQLDatasource - please tell me what I am doing wrong.

This proc, when fed to a sqldatasource, fails in the designer with #temp does not exists.

CREATE PROCEDURE dbo.repTest_Temp
AS
BEGIN

CREATE TABLE #Temp
(
[iTestID] uniqueidentifier,
[bTest] [bit],
[cTest] [varchar]
)

INSERT INTO #Temp
SELECT *
FROM tTest

SELECT *
FROM #Temp

END

try:

CREATE PROCEDURE dbo.repTest_Temp
AS
BEGIN

CREATE TABLE #Temp
(
[iTestID] uniqueidentifier,
[bTest] [bit],
[cTest] varchar(10)
)

INSERT INTO #Temp
SELECT *
FROM tTest

SELECT *
FROM #Temp

END

It still won't read the schema, but you can do whatever you want to by manually entering the fields you need. I bound it to a gridview, and created 3 bound fields, adding the name of each field, and it showed up in my page just fine -- although I replaced the INSERT statement with "INSERTINTO #zzTemp(iTestID,bTest,cTest)VALUES(newid(),0,'test')"


|||

That's the same proc I posted - and no it won't load in a sqldatasource. I wasn't asking for a work around - I'm fully aware I can manually bind the grid. Kinda defeats the purpose of having a visual designer, don't you think?

What I asked was IF you can use a proc in a SQLDatasource that has it's final select from a temp table. I thought I made this clear by supplying the proc. If you can't, that's yet ONE more thing screwed up with the visual designer.

It's still blowing me away how useless the visual designer is to do any real work.

|||

I changed the sproc, if you notice the definition of one of your fields from [varchar] to varchar(10).

Let me try and make this clearer for you:

What I asked was IF you can use a proc in a SQLDatasource that has it's final select from a temp table. I thought I made this clear by supplying the proc.

What I answered was yes. You can use a proc in a SQLDatasource that has it's final select from a temp table. I thought I made this clear by supplying the proc I used, as well as how I implemented it, and got a gridview to databind to said sproc.

From your last message, you aren't interested in how, you just want to complain. I'm not here to make you feel better. I gave you a solution on how to get done what you needed, and it took me a total of 10 minutes. Take it and use it, or complain some more. I'm done with the thread.

|||

i realize this is considerably after the fact for the originating parties, i will still post my findings for anyone else that might experience this problem. i would define the problem as visual studio barking whenever i tried to drag a stored procedure to the .xsd designer interface which selected from a temp table. im posting here because this is the only thread i could find on the subject. i have rewritten the original posted procedure to show the solution. simply use a TABLE variable instead of a temp table.

CREATE PROCEDURE dbo.repTest_Temp
AS

DECLARE @.Temp TABLE (iTestID uniqueidentifier,
bTest bit,
cTest varchar(10))

INSERT @.Temp
SELECT *
FROM tTest

SELECT *
FROM @.Temp

this worked like a charm for me. hopefully someone else will find this information useful!

|||Another solution is to use Global Temp table instead of local temp table which goes out of scope quickly. ## global temp table and # local temp table. Hope this helps.

No temp table

Is it possible to rewrite this delete so that a temp table isn't used?
key_1 and date_key form the primary key. I want to remove any rows with the
same key_1 and a date_key greater than today's date.
Cheers!
declare @.today datetime
select @.today = getdate()
select key_1, date_key
into #temp
from my_table
where date_key > @.today
group by key_1 having count(*) > 1
delete my_table
from #temp, my_table m
where #temp.date_key = m.date_key
and #temp.key_1 = m.key_1Gyruss wrote:
> Is it possible to rewrite this delete so that a temp table isn't used?
> key_1 and date_key form the primary key. I want to remove any rows
> with the same key_1 and a date_key greater than today's date.
> Cheers!
> declare @.today datetime
> select @.today = getdate()
> select key_1, date_key
> into #temp
> from my_table
> where date_key > @.today
> group by key_1 having count(*) > 1
>
> delete my_table
> from #temp, my_table m
> where #temp.date_key = m.date_key
> and #temp.key_1 = m.key_1
Untested:
Delete From my_table
Where date_key > @.today
and key_1 IN (
Select key_1
From my_table
Where date_key > @.today
group by key_1 having count(*) > 1)
David Gugick
Imceda Software
www.imceda.com|||DELETE FROM My_table
WHERE EXISTS
(SELECT *
FROM My_table AS M
WHERE M.date_key = Mytable.date_key
AND M..key_1 = Mytable.key_1);
You probably want to learn SQL and stop using the dialect with the FROM
clause and joins in it. The results are unpredictable as well as not
portable.|||The SELECT statement you posted isn't legal so I'm not certain what you
intended. You also didn't tell us the primary key, which might have
helped. Do you have a key?
DELETE FROM my_table
WHERE date_key > CURRENT_TIMESTAMP
AND EXISTS
(SELECT *
FROM my_table AS M
WHERE key_1 = my_table.key_1
AND date_key <= CURRENT_TIMESTAMP)
David Portas
SQL Server MVP
--|||>> I want to remove any rows with the same key_1 and a date_key greater
than today's date <<
Opps! I read to mean that if there is a group with all members in the
future, we leave them alone. If there is a group with all members in
the past or present, we leave them alone. If there is a group with
members in the past or present or future, we delete the future members.
DELETE FROM My_table
WHERE Mytable.date_key > CURRENT_TIMESTAMP
AND EXISTS
(SELECT *
FROM My_table AS M
WHERE AND M.key_1 = Mytable.key_1
AND M.date_key <= CURRENT_TIMESTAMP );|||On Sat, 26 Feb 2005 09:50:04 +1100, Gyruss wrote:

>Is it possible to rewrite this delete so that a temp table isn't used?
>key_1 and date_key form the primary key. I want to remove any rows with th
e
>same key_1 and a date_key greater than today's date.
>Cheers!
>declare @.today datetime
>select @.today = getdate()
> select key_1, date_key
> into #temp
> from my_table
> where date_key > @.today
>group by key_1 having count(*) > 1
>
>delete my_table
> from #temp, my_table m
> where #temp.date_key = m.date_key
> and #temp.key_1 = m.key_1
>
Hi Gyruss,
I'm . Your text says "any rows with the same key_1 and a
date_key greater than todays's date". But the query says "any rows with
the same key_1 and a data_key greater than today's date, unless only one
such row exists for this key_1".
Try this one. I didn't test it, since you didn't post CREATE TABLE and
INSERT statements to test it with.
DELETE my_table
WHERE date_key > CURRENT_TIMESTAMP
AND (SELECT COUNT(*)
FROM my_table AS a
WHERE a.key_1 = my_table.key_1
AND a.date_key > CURRENT_TIMESTAMP) > 1
This mimics your query. If the text description is accurate, you can
reduce this to
DELETE my_table
WHERE date_key > CURRENT_TIMESTAMP
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)