-
Stored proc. parameter tablename
Hi.
I try to delete all fields from a table.
I create a SP but i always receive the same error
if exists (select * from sysobjects where id = object_id('dbo.sp_DeleteDnsIp')
and sysstat & 0xf = 4)
drop procedure dbo.sp_DeleteDnsIp
GO
CREATE PROCEDURE sp_DeleteDnsIp (
@NomTable varchar(75)
)
AS
Delete From @NomTable
The error:Line 13: Incorrect syntax near '@NomTable'.
Please help me
-
Re: Stored proc. parameter tablename
SQL is trying to delete the data in a table named '@NomTable' instead of the
table name contained in the variable @NomTable. You must first build a string
that contains the delete statement and then use the EXEC() function. Replace
the delete statement in your stored procedure with the following:
DECLARE @SQL varchar(255)
SELECT @SQL = 'DELETE FROM ' + @NomTable
EXEC(@SQL)
I hope this helps.
- Jason
"Ghislain Tanguay" <ghislaintanguay3@hotmail.com> wrote:
>
>Hi.
>I try to delete all fields from a table.
>I create a SP but i always receive the same error
>
>if exists (select * from sysobjects where id = object_id('dbo.sp_DeleteDnsIp')
>and sysstat & 0xf = 4)
> drop procedure dbo.sp_DeleteDnsIp
>
>GO
>CREATE PROCEDURE sp_DeleteDnsIp (
> @NomTable varchar(75)
> )
> AS
> Delete From @NomTable
>
>The error:Line 13: Incorrect syntax near '@NomTable'.
>
>Please help me
>
>
-
Re: Stored proc. parameter tablename
Tks Jason.
It just work fine.
Have a nice easter week-end
And god bless all
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks