Board index » cppbuilder » Who can Help me, It's a Proceduer Question,Thanks

Who can Help me, It's a Proceduer Question,Thanks


2004-02-14 09:17:33 PM
cppbuilder0
CREATE PROCEDURE ct_createtable
@TableName varchar(20) = NULL
AS
IF EXISTS (SELECT name FROM sysobjects
WHERE name = @TableName AND type = 'u')
DROP TABLE @TableName
where is it error at?
 
 

Re:Who can Help me, It's a Proceduer Question,Thanks

CREATE PROCEDURE ct_createtable
@TableName varchar(20) = NULL
AS
DECLARE @sql varchar(2000)
SELECT @sql='DROP TABLE @TableName'
IF EXISTS (SELECT name FROM sysobjects
WHERE name = @TableName AND type = 'u')
EXECUTE (@sql)
GO
Such as,there is no error at grammar,but it shows the error at the line 1 on
running.
 

Re:Who can Help me, It's a Proceduer Question,Thanks

Try this
set @sql = 'drop table ' + @tablename
and not
SELECT @sql='DROP TABLE @TableName'
Ricardo
ignativs wrote:
Quote
CREATE PROCEDURE ct_createtable
@TableName varchar(20) = NULL
AS
DECLARE @sql varchar(2000)

SELECT @sql='DROP TABLE @TableName'
IF EXISTS (SELECT name FROM sysobjects
WHERE name = @TableName AND type = 'u')
EXECUTE (@sql)
GO


Such as,there is no error at grammar,but it shows the error at the line 1 on
running.



 

{smallsort}