Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2013, 05:49 PM
raosistemas raosistemas is offline
Junior Member
 
Join Date: Apr 2013
Location: Sao Paulo - Brazil
Posts: 3
Default Problem to make a sql script (mysql)

explaining... I have 2 tables...

costumers
------------
cli_code Int
cli_name varchar 60
cli_blocked tinyint 1

sells
-------
ven_data date
ven_total float

What i want...--------------------------------------------
in the start of my program execution i have to do this...
if there is no sell in the last 2 months i want to mark the costumer with '1' in the field blocked... (mark the costumer as blocked)

how can I do this?
Thanks!
Reply With Quote
  #2  
Old 04-25-2013, 07:52 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

something like:
Code:
update 
  customers
set blocked = 1
where (select count(*) from sells where ven_cli_code=customers.cli_code and ven_data > (GetDate() - 60)) = 0
Ofcourse you should use some decrease month function instead of the 60, but this is to get the general idea
Reply With Quote
  #3  
Old 04-25-2013, 03:49 PM
raosistemas raosistemas is offline
Junior Member
 
Join Date: Apr 2013
Location: Sao Paulo - Brazil
Posts: 3
Default

Thanks a lot!
RAO!
Reply With Quote
Reply

Tags
database, mysql, script

Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:06 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.