tags:

views:

28

answers:

1

Error SQL query:

UPDATE  `wfg_db`.`employee` SET  `DOB` = 
   (DECLARE@mm INT 
    DECLARE@xm INT 
    SET @mm =1 
    SET @xm =13 
    DECLARE@md 
    INT DECLARE@xd 
    INT SET @md =1 
    SET @xd =29 
    DECLARE@my INT 
    DECLARE@xy INT 
    SET @my =1900 
    SET @xy =2009 SELECT CAST( CAST( (

@xm - @mm
) * RAND( ) + @mm AS INT ) AS VARCHAR( 2 ) ) +  '/' + CAST( CAST( (
@xd - @md
) * RAND( ) + @md AS INT ) AS VARCHAR( 2 ) ) +  '/' + CAST( CAST( (
@xy - @my
) * RAND( ) + @my AS INT ) AS VARCHAR( 4 ) ) AS DATE ) 
WHERE  `employee`.`id`

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @mm int DECLARE @xm int SET @mm = 1 SET @xm = 13 DECLARE @md int ' at line 1

+2  A: 

Does this do what you need?

 UPDATE  `wfg_db`.`employee` SET  `DOB` = 
   cast(ADDDATE('1900-01-01',rand()*40176) as date)
   /*    WHERE  `employee`.`id` = What?*/
Martin Smith
thanks very much it worked man/.........yahoooooooooooooo
i want to restrict the random values between 1900 to 1985 onlywht modification required?
Change the number to 31411 from 40176
Martin Smith
dear age goes in -ve numbers
I have no idea what that comment is meant to mean!
Martin Smith
date of birth goes into the futurelike 12/2/2029whts this?
No idea. Are you sure you're using `cast(ADDDATE('1900-01-01', rand()*31411) as date)`?
Martin Smith
yup i m usin d same but it genarates future dates...:(
Well it definitely shouldn't do and doesn't for me.
Martin Smith