DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Ghislain Tanguay Guest

    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



  2. #2
    Jason Rein Guest

    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
    >
    >



  3. #3
    Ghislain Guest

    Re: Stored proc. parameter tablename


    Tks Jason.
    It just work fine.

    Have a nice easter week-end

    And god bless all

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links