Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trying to use a variable in a EXEC statement

Author  Topic 

ashoktheagarajan
Starting Member

2 Posts

Posted - 2009-03-05 : 05:20:44
ALTER PROCEDURE FindMaxDateofData
AS
BEGIN

Declare @date datetime

EXEC ('Declare @datetime Use Coradiant Select @date = max(date) from Raw_data
EXEC ('Use Metadatamgmt Insert into LastUpdateDates values(1,@date,00:00:00)')

END

What I am trying to do is to find out the maximum date till which the data has been downloaded. Coradiant is the name of the Data base and Raw data is the name of the table.

Metadatamgmt is the name of the database where i have the lastupdatedates table where i input the last date till which the data has been filled.

But when i try to execute these three statements, it says must declare variable @date.

Please help

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-05 : 05:25:21
Why use exec when nothing is dynamic.
Might as well change it to..

CREATE PROCEDURE FindMaxDateofData
AS
BEGIN

Declare @date datetime
Select @date = max(date) from Coradiant..Raw_data
Insert into Metadatamgmt..LastUpdateDates values(....)

END
Go to Top of Page

ashoktheagarajan
Starting Member

2 Posts

Posted - 2009-03-05 : 05:29:58
Thanks ! It worked. Also if i am not bothering you. Is there a way to find out when was the last insert made on a particular table.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-05 : 05:31:09
A few ways are listed here.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=120939
Go to Top of Page
   

- Advertisement -