Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Not able to use a TRUNCATE command in

Posted on 2016-08-01
4
56 Views
Last Modified: 2016-08-04
I am not able to create the below Sybase stored procedure. The Sybase error indicates that it does not like the line where
my TRUNCATE command is. The error message says incorrect syntax near @inTable. If I comment out that line where the TRUNCATE is, I can create the stored procedure. However I need to truncate the table. What is wrong with the line where my TRUNCATE statement is located? Can an expert help me out? What is odd is that I can run the truncate with in the command line if I actually
use the name of the table. Like TRUNCATE Table sampleTable

CREATE PROCEDURE dbo.spTruncateTable
@inTable VARCHAR(100) = NULL
AS
 BEGIN
   TRUNCATE TABLE @inTable
   PRINT 'Table Truncated'
 END
0
Comment
Question by:brgdotnet
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Phil Davidson earned 500 total points
ID: 41738329
I think that TRUNCATE cannot operate against a table in a loop based on a that same table.  TRUNCATE is a DDL command.  This means the definition of the table is eliminated.  DELETE is a DML command.  I think a loop like that can delete data from the tables.  But when you nest a truncate to eliminate a table created in the procedure, the Sybase database engine gets confused.  Delete the content of the table would be different.
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 41738409
I could use the delete command. But Sir, what loop are you talking about? The one which exists in the TRUNCATE function developed by Sybase? I think that is what you meant, because in the above code I am not using a loop Sir.
0
 
LVL 13

Expert Comment

by:alpmoon
ID: 41739669
The problem is using a variable in truncate command. It is not allowed. You can only do it through execute command:

execute ( 'TRUNCATE TABLE  '+@inTable)
0
 
LVL 13

Expert Comment

by:alpmoon
ID: 41739680
By the way I assumed that it is ASE, if you are trying it on ASA the syntax would be different. Let me know what product and version you are using if this syntax doesn't work.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question