By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,570 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,570 IT Pros & Developers. It's quick & easy.

Issue with triggers, if statement,and count(); its rather urgent.

P: 2
Hi All,
I have 3 rather Long Questions that are causing alot of trouble:
I would appreciate all the help i can get and tried to use A post sent to atli in the past but it did not help...

!) I have an events table, within the events table I have 7 columns,
Expand|Select|Wrap|Line Numbers
  1. Alias varchar (30)
  2. Progress int(1)
  3. Val double
  4. Stamp timestamp
  5. ID auto increment.
  6. date date
  7. time time
My problem is very similar to Atli, where he wanted to perform a mysql if statement on the result of a count function.
Basically, My progress column is intented to hold a '1' or a '0'

so here we go....

if the result of the count of occurance Alias = 'Test' modulus 2 (i.e. count(Alias) mod 2)
is equivelant to '0', then we wish to input a '1' into the 'progress' column of my 'events' table, if the result of count(Alias) mod 2 where Alias = 'Test' equals '1' then i would like to put in a '0' into my 'progress' column of my 'events' table.

This process must happen every time that a record is entered with the Alias = 'Test' - so that probably means that we need to put it in a trigger of some sort.

Also is there a way for replacing
Expand|Select|Wrap|Line Numbers
  1.  Alias = 'Test' 
Expand|Select|Wrap|Line Numbers
  1.  Alias = 'select distinct alias from events
'????? so that we have something like this:

Expand|Select|Wrap|Line Numbers
  1. Select count(Alias) mod 2 from events where Alias = Select distinct Alias from events. and then enclose that in an if statement and then a trigger.
This 2nd query is ideally what we would like because my table could potentially hold 1000 records or even more.


2) in the same 'events' table i have a stamp column, holding a timestamp that has been inserted into my table, what i need to do is, to get what ever is in the stamp column, and cut it into time and date, the way i thought would be good was to insert that value into the date and time columns that are in my events table????
and again this would have to be for every row in my table, and every newly inserted row, and would therefore require a trigger....could someone help me out at all?
this has also given me a huge hadache.

one Last Question: will the trigger come into action every time the MYSQL server instance is initialised, you see everything is local at the moment on my laptop, and is configured so that the instance starts upon boot, will that mean that the triggers will also come into play asap? (OS:windows xp 32 bit)

Thankyou very much for your help in advance - this is very urgent and i have been bouncing my head of walls for days.
I really appreciate your time and effort, may god help you all!

Please Also send reply to:
thanks again
Jan 31 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.