If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Help needed : Truncating a table based on a condition

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-04-11, 01:57
krish_princi krish_princi is offline
Registered User
 
Join Date: Aug 2011
Posts: 5
Help needed : Truncating a table based on a condition

Dear Friends,

I am writing a script and want to execute from the OS level. I have one doubt, How do I truncate the table based on some condition. Here let us assume that I want to truncate the whole table if the count(*) reaches 200,000. Please provide syntaxes for the same.
Reply With Quote
  #2 (permalink)  
Old 09-04-11, 03:49
krish_princi krish_princi is offline
Registered User
 
Join Date: Aug 2011
Posts: 5
Pls reply

Please reply .. :'( im eagerly waiting.
Reply With Quote
  #3 (permalink)  
Old 09-04-11, 08:39
pradyut.dhara pradyut.dhara is offline
Registered User
 
Join Date: May 2011
Posts: 28
Help needed : Truncating a table based on a condition

Hi,
Following syntax can be used.

Code:
if exists(select 1 from T1 having count(1)>200000 )
begin
	exec ('truncate table T1')
end
go
OR

Code:
if (select count(*) from T1) >200000
begin
	exec ('truncate table T1')
end
go
Reply With Quote
  #4 (permalink)  
Old 09-07-11, 02:05
krish_princi krish_princi is offline
Registered User
 
Join Date: Aug 2011
Posts: 5
Thank you

Thank you very much friend.
Reply With Quote
Reply

Tags
sybase, truncating table

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On