Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Argument-Passing Help

Status
Not open for further replies.

christywarner

Programmer
Apr 14, 2003
32
0
0
US
Hi,

I want to create a procedure "EXISTDROP" that
will drop a SQL Server table where the table name
is passed from my VB app. Here is what I have
but I'm getting the error message:

"Incorrect syntax near @TABLENAME on line 5"

CREATE PROCEDURE EXISTDROP
@TABLENAME VARCHAR(75) AS
IF EXISTS (SELECT name FROM sysobjects WHERE NAME= @TABLENAME)
DROP @TABLENAME
GO

Thanks for any help!
Christy.

 
never-mind, figured it out, it needed
some brackets around the table-name in
the DROP statement. . .

Thanks,
Christy.
 
Have you tested it to make sure it actually works?

Putting brackets around the table name makes the syntax checker happy, but doesn't make it drop the table whose name is stored in the variable. Instead, it will try to drop the table '@tablename' which is not one of your tables, I am sure.

You'll need to use dynamic SQL to accomplish this task.

As for the advisability of such a stored procedure, why can't you just use templates? It's good to avoid dynamic SQL when possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top