Home All Groups Group Topic Archive Search About

Stored Proc - DELETE FROM @TableName

Author
24 Sep 2005 4:07 AM
hushtech
I'm attempting to delete contents of @TableName where @TableName is
an input arg to my stored procedure as follows. How do I execute this query?
Or is there a simpler way to do this?  This must be really trivial I suspect.

CREATE PROCEDURE sp_DeleteRecordset
    @TableName  varchar(50)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @QRY varchar(100)
    Set @QRY = "DELETE FROM " + @TableName
    ???????
END
GO

thanks,  jack

Author
24 Sep 2005 4:36 AM
Yosh
CREATE PROCEDURE sp_DeleteRecordset
@TableName  varchar(50)
AS
BEGIN
SET NOCOUNT ON
DECLARE @QRY varchar(100)
Set @QRY = "DELETE FROM " + @TableName

EXEC (@QRY)

END
GO

Show quote
"hushtech" <husht***@discussions.microsoft.com> wrote in message
news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
> I'm attempting to delete contents of @TableName where @TableName is
> an input arg to my stored procedure as follows. How do I execute this
> query?
> Or is there a simpler way to do this?  This must be really trivial I
> suspect.
>
> CREATE PROCEDURE sp_DeleteRecordset
> @TableName  varchar(50)
> AS
> BEGIN
> SET NOCOUNT ON
> DECLARE @QRY varchar(100)
> Set @QRY = "DELETE FROM " + @TableName
> ???????
> END
> GO
>
> thanks,  jack
Author
24 Sep 2005 4:51 AM
hushtech
Thanks Yosh! 
I just couldn't get the form of the EXEC right.

jack-

Show quote
"Yosh" wrote:

> CREATE PROCEDURE sp_DeleteRecordset
> @TableName  varchar(50)
> AS
> BEGIN
> SET NOCOUNT ON
> DECLARE @QRY varchar(100)
> Set @QRY = "DELETE FROM " + @TableName
>
> EXEC (@QRY)
>
> END
> GO
>
> "hushtech" <husht***@discussions.microsoft.com> wrote in message
> news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
> > I'm attempting to delete contents of @TableName where @TableName is
> > an input arg to my stored procedure as follows. How do I execute this
> > query?
> > Or is there a simpler way to do this?  This must be really trivial I
> > suspect.
> >
> > CREATE PROCEDURE sp_DeleteRecordset
> > @TableName  varchar(50)
> > AS
> > BEGIN
> > SET NOCOUNT ON
> > DECLARE @QRY varchar(100)
> > Set @QRY = "DELETE FROM " + @TableName
> > ???????
> > END
> > GO
> >
> > thanks,  jack
>
>
>
Author
24 Sep 2005 4:56 AM
Yosh
I could tell you knew what you were doing. It's those damn parens that get
me every now and then. =0}



Show quote
"hushtech" <husht***@discussions.microsoft.com> wrote in message
news:0626D726-1CC5-46F3-A111-C0CD91B70FDE@microsoft.com...
> Thanks Yosh!
> I just couldn't get the form of the EXEC right.
>
> jack-
>
> "Yosh" wrote:
>
>> CREATE PROCEDURE sp_DeleteRecordset
>> @TableName  varchar(50)
>> AS
>> BEGIN
>> SET NOCOUNT ON
>> DECLARE @QRY varchar(100)
>> Set @QRY = "DELETE FROM " + @TableName
>>
>> EXEC (@QRY)
>>
>> END
>> GO
>>
>> "hushtech" <husht***@discussions.microsoft.com> wrote in message
>> news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
>> > I'm attempting to delete contents of @TableName where @TableName is
>> > an input arg to my stored procedure as follows. How do I execute this
>> > query?
>> > Or is there a simpler way to do this?  This must be really trivial I
>> > suspect.
>> >
>> > CREATE PROCEDURE sp_DeleteRecordset
>> > @TableName  varchar(50)
>> > AS
>> > BEGIN
>> > SET NOCOUNT ON
>> > DECLARE @QRY varchar(100)
>> > Set @QRY = "DELETE FROM " + @TableName
>> > ???????
>> > END
>> > GO
>> >
>> > thanks,  jack
>>
>>
>>
Author
24 Sep 2005 4:38 AM
Jerry Spivey
Try:

CREATE PROC usp_TruncateTable
@TableName varchar(50)
AS
DECLARE @SQL varchar(150)
SET @SQL = 'TRUNCATE TABLE [' + @TableName + ']'
EXEC (@SQL)

HTH

Jerry
Show quote
"hushtech" <husht***@discussions.microsoft.com> wrote in message
news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
> I'm attempting to delete contents of @TableName where @TableName is
> an input arg to my stored procedure as follows. How do I execute this
> query?
> Or is there a simpler way to do this?  This must be really trivial I
> suspect.
>
> CREATE PROCEDURE sp_DeleteRecordset
> @TableName  varchar(50)
> AS
> BEGIN
> SET NOCOUNT ON
> DECLARE @QRY varchar(100)
> Set @QRY = "DELETE FROM " + @TableName
> ???????
> END
> GO
>
> thanks,  jack
Author
24 Sep 2005 4:44 AM
Yosh
Just know that if you issue a TRUNCATE statement on a table,  it removes all
rows from a table without logging the individual row deletes.


Show quote
"Jerry Spivey" <jspi***@vestas-awt.com> wrote in message
news:eIuaWHMwFHA.2540@TK2MSFTNGP09.phx.gbl...
> Try:
>
> CREATE PROC usp_TruncateTable
> @TableName varchar(50)
> AS
> DECLARE @SQL varchar(150)
> SET @SQL = 'TRUNCATE TABLE [' + @TableName + ']'
> EXEC (@SQL)
>
> HTH
>
> Jerry
> "hushtech" <husht***@discussions.microsoft.com> wrote in message
> news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
>> I'm attempting to delete contents of @TableName where @TableName is
>> an input arg to my stored procedure as follows. How do I execute this
>> query?
>> Or is there a simpler way to do this?  This must be really trivial I
>> suspect.
>>
>> CREATE PROCEDURE sp_DeleteRecordset
>> @TableName  varchar(50)
>> AS
>> BEGIN
>> SET NOCOUNT ON
>> DECLARE @QRY varchar(100)
>> Set @QRY = "DELETE FROM " + @TableName
>> ???????
>> END
>> GO
>>
>> thanks,  jack
>
>
Author
24 Sep 2005 4:51 AM
Jerry Spivey
Yosh,

Yes...I wrote it that way to increase the performance of his delete while
minimizing the amount of logging involved.

Jerry
Show quote
"Yosh" <yoshi@nospam.com> wrote in message
news:%23wv8fKMwFHA.3400@TK2MSFTNGP14.phx.gbl...
> Just know that if you issue a TRUNCATE statement on a table,  it removes
> all rows from a table without logging the individual row deletes.
>
>
> "Jerry Spivey" <jspi***@vestas-awt.com> wrote in message
> news:eIuaWHMwFHA.2540@TK2MSFTNGP09.phx.gbl...
>> Try:
>>
>> CREATE PROC usp_TruncateTable
>> @TableName varchar(50)
>> AS
>> DECLARE @SQL varchar(150)
>> SET @SQL = 'TRUNCATE TABLE [' + @TableName + ']'
>> EXEC (@SQL)
>>
>> HTH
>>
>> Jerry
>> "hushtech" <husht***@discussions.microsoft.com> wrote in message
>> news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
>>> I'm attempting to delete contents of @TableName where @TableName is
>>> an input arg to my stored procedure as follows. How do I execute this
>>> query?
>>> Or is there a simpler way to do this?  This must be really trivial I
>>> suspect.
>>>
>>> CREATE PROCEDURE sp_DeleteRecordset
>>> @TableName  varchar(50)
>>> AS
>>> BEGIN
>>> SET NOCOUNT ON
>>> DECLARE @QRY varchar(100)
>>> Set @QRY = "DELETE FROM " + @TableName
>>> ???????
>>> END
>>> GO
>>>
>>> thanks,  jack
>>
>>
>
>
Author
24 Sep 2005 4:55 AM
Yosh
Thanks Jerry!

I know you knew what it did. I just wanted to make sure he did. Very good
point!!! =0}


Show quote
"Jerry Spivey" <jspi***@vestas-awt.com> wrote in message
news:uxH3gOMwFHA.3300@TK2MSFTNGP09.phx.gbl...
> Yosh,
>
> Yes...I wrote it that way to increase the performance of his delete while
> minimizing the amount of logging involved.
>
> Jerry
> "Yosh" <yoshi@nospam.com> wrote in message
> news:%23wv8fKMwFHA.3400@TK2MSFTNGP14.phx.gbl...
>> Just know that if you issue a TRUNCATE statement on a table,  it removes
>> all rows from a table without logging the individual row deletes.
>>
>>
>> "Jerry Spivey" <jspi***@vestas-awt.com> wrote in message
>> news:eIuaWHMwFHA.2540@TK2MSFTNGP09.phx.gbl...
>>> Try:
>>>
>>> CREATE PROC usp_TruncateTable
>>> @TableName varchar(50)
>>> AS
>>> DECLARE @SQL varchar(150)
>>> SET @SQL = 'TRUNCATE TABLE [' + @TableName + ']'
>>> EXEC (@SQL)
>>>
>>> HTH
>>>
>>> Jerry
>>> "hushtech" <husht***@discussions.microsoft.com> wrote in message
>>> news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
>>>> I'm attempting to delete contents of @TableName where @TableName is
>>>> an input arg to my stored procedure as follows. How do I execute this
>>>> query?
>>>> Or is there a simpler way to do this?  This must be really trivial I
>>>> suspect.
>>>>
>>>> CREATE PROCEDURE sp_DeleteRecordset
>>>> @TableName  varchar(50)
>>>> AS
>>>> BEGIN
>>>> SET NOCOUNT ON
>>>> DECLARE @QRY varchar(100)
>>>> Set @QRY = "DELETE FROM " + @TableName
>>>> ???????
>>>> END
>>>> GO
>>>>
>>>> thanks,  jack
>>>
>>>
>>
>>
>
>
Author
24 Sep 2005 4:55 AM
hushtech
Thanks Jerry,
I see the proper EXEC form, and your naming is
much more informative.

jack-

Show quote
"Jerry Spivey" wrote:

> Try:
>
> CREATE PROC usp_TruncateTable
> @TableName varchar(50)
> AS
> DECLARE @SQL varchar(150)
> SET @SQL = 'TRUNCATE TABLE [' + @TableName + ']'
> EXEC (@SQL)
>
> HTH
>
> Jerry
> "hushtech" <husht***@discussions.microsoft.com> wrote in message
> news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
> > I'm attempting to delete contents of @TableName where @TableName is
> > an input arg to my stored procedure as follows. How do I execute this
> > query?
> > Or is there a simpler way to do this?  This must be really trivial I
> > suspect.
> >
> > CREATE PROCEDURE sp_DeleteRecordset
> > @TableName  varchar(50)
> > AS
> > BEGIN
> > SET NOCOUNT ON
> > DECLARE @QRY varchar(100)
> > Set @QRY = "DELETE FROM " + @TableName
> > ???????
> > END
> > GO
> >
> > thanks,  jack
>
>
>
Author
24 Sep 2005 5:00 AM
Yosh
I like his use of the "brackets" around the table name.


Show quote
"hushtech" <husht***@discussions.microsoft.com> wrote in message
news:6EEE4CE7-072B-4604-BC27-CD4953067CA6@microsoft.com...
> Thanks Jerry,
> I see the proper EXEC form, and your naming is
> much more informative.
>
> jack-
>
> "Jerry Spivey" wrote:
>
>> Try:
>>
>> CREATE PROC usp_TruncateTable
>> @TableName varchar(50)
>> AS
>> DECLARE @SQL varchar(150)
>> SET @SQL = 'TRUNCATE TABLE [' + @TableName + ']'
>> EXEC (@SQL)
>>
>> HTH
>>
>> Jerry
>> "hushtech" <husht***@discussions.microsoft.com> wrote in message
>> news:638E8161-3D2A-4878-A06D-E1A126EC37D1@microsoft.com...
>> > I'm attempting to delete contents of @TableName where @TableName is
>> > an input arg to my stored procedure as follows. How do I execute this
>> > query?
>> > Or is there a simpler way to do this?  This must be really trivial I
>> > suspect.
>> >
>> > CREATE PROCEDURE sp_DeleteRecordset
>> > @TableName  varchar(50)
>> > AS
>> > BEGIN
>> > SET NOCOUNT ON
>> > DECLARE @QRY varchar(100)
>> > Set @QRY = "DELETE FROM " + @TableName
>> > ???????
>> > END
>> > GO
>> >
>> > thanks,  jack
>>
>>
>>

AddThis Social Bookmark Button