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 2000 Forums
 SQL Server Development (2000)
 Get Table

Author  Topic 

pubs
Starting Member

3 Posts

Posted - 2005-06-17 : 09:05:08
Hi,

Im creating a user defined function which takes as a parameter the table name.

My problem is i cant do this:

Delete from @Table_name


any clue how to do this?

thanks in advance

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-17 : 09:10:55
in a function you can't.
write it as a stored procedure.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

pubs
Starting Member

3 Posts

Posted - 2005-06-17 : 09:52:06
Doesnt work! :\ what now?


CREATE PROCEDURE DeleteTable
@TableName varchar(20)
AS

begin

delete from @tablename

end


GO
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-17 : 09:54:21
exec('delete from ' + @tablename)

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Thrasymachus
Constraint Violating Yak Guru

483 Posts

Posted - 2005-06-17 : 09:54:49
you need to use sp_executesql.

Sean Roussy

Please backup all of your databases including master, msdb and model on a regular basis. I am tired of telling people they are screwed. The job you save may be your own.
Go to Top of Page

pubs
Starting Member

3 Posts

Posted - 2005-06-17 : 11:22:57
Thanks a lot spirit1 and Thrasymachus ;)
Go to Top of Page
   

- Advertisement -