[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Not able to use a TRUNCATE command in

Posted on 2016-08-01
4
Medium Priority
?
108 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
[X]
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
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Phil Davidson earned 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

649 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