Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL delete/truncate table Post Reply Post New Topic
Author Message
ChrisOs
Newbie
Newbie


Joined: 04 Aug 2011
Online Status: Offline
Posts: 6
Quote ChrisOs Replybullet Topic: SQL delete/truncate table
     Posted: 14 Sep 2011 at 4:17am
Hello,
 
As part of my report I populate a table then reference it in several following subreports.
 
The issue I'm having is that I need to clear all the data from my table after using it to allow the report to run again (and not get multiple results)
 
To do this I have tried to add a sub report at the very end (and start) of my report with the SQL command truncate table <tablename> or delete <tablename> or delete <tablename> where 1 = 1.
 
When I try truncate I get an error saying that I don't have permission which is why I switched to delete, this runs fine but the table doesn't get deleted...
 
Any thoughts as to why this isn't working/how I can clear my table? I have thought of setting up a separate scheduled job to delete the table contents however I do also need to run the report several times with different parameters so this isn't an ideal solution.
 
Any help will be much appreciated!
 
Thanks
Chris
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 Sep 2011 at 3:52am
well, my standard answer would be to create a stored proc and get the main report's data from that.  In the stored poc you could truncate the table without any issues.
 
While, I suppose it is possible to have CR modify data on the database, 1) I have never tried it, because 2) I think that the basic design of CR is to read data not modify.
 
I understand the need to fill a table with data so that one can access it...
In thinking about it, you could probably have the stored proc do nothing else but truncate the table and return something, say true, this way CR 'thinks' it is returning data, and then you could have your report continue operating as it does now...
 
I guess you could do the truncation in a command object, but i would be leery of that I don't in which order CR executes commands, in which case your report would/could be wrong and it would be very hard to debug.
 
If you delete the table, then you must have code that creates it again...
 
Since all my reports drive off of stored procs, that is the path that I would try first, but that is me.
 
HTH
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum