Solved

Not able to use a TRUNCATE command in

Posted on 2016-08-01
4
34 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now