#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0

    Using a value from another table in a where clause...


    This is the code I have now...

    Code:
    DELIMITER $$
    
    CREATE DEFINER=`lifeprojectrpg`@`localhost` PROCEDURE `BankingTableDump`(IN rowid INT(12))
    BEGIN
    		SELECT playeruid, money 
    		FROM banking
    		WHERE id = rowid;
        END
    I want to add a date comparison to the where clause.

    So basically the column is in the "information" table and it's called "lastlogin", it's in the format yyyymmdd (20121108). I want to subtract that from the current date and then if that equals greater than 15 or whatever integer then I want the whole query to return -1 and that's all, nothing else, but if it doesn't, if it equals less then run the above code normally and return the playeruid and the money. The lastlogin should be selected using the playerid which is selected from the "banking" table.

    I've been trying to work this out for a couple of hours now and it's just beyond me so I would appreciate any help .
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0
    Anyone? .
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,927
    Rep Power
    378
    Perhaps you're trying to solve too many problems at once:
    - how to write a procedure
    - how to write a query
    - how to return two different kinds of thing (-1 vs result set)

    If it was me, I'd try breaking it down into smaller steps starting with 'I have a table like this... CREATE etc... with data like this... INSERT etc... and another table like this...CREATE etc ... with data like this... How do I get a result like this?'
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0
    I know how to do it in two different querys but I want to condense it into one and I can't figure out how to, which is why I'm asking for help .

IMN logo majestic logo threadwatch logo seochat tools logo