Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006
    Posts
    2

    Unanswered: MSSQL to MySQL Query Convertion

    Hi this code was originally from MSSQL query. However, I need to convert this to MYSQL query. There are syntax errors and I do not know what it means. It says there is some error in the DECLARE section. Thanks!

    I reviewed tutorials, I added semi colons and other things but still no progress.


    PHP Code:
    DECLARE $D1 as datetime, @D2 as datetime
    SET 
    @D1 '01/01/2001'
    SET @D2 '01/31/2002'

    SELECT A.BRA.DEALNOA.SEQ, @D1 AS DATEFR, @D2 AS DATETOA.CCYA.VDATEA.MDATE,
           
    A.PRODTYPEA.CCYAMT,
           
    ADB = ( ABS(A.CCYAMT) *
                   CASE 
    WHEN (A.VDATE <= @D1 AND A.MDATE > @D2THEN (ABS(DATEDIFF(dd, @D2, @D1)))+1
                WHEN 
    (A.MDATE  = @D2 AND A.VDATE < @D1THEN ABS(DATEDIFF(ddA.MDATE, @D1))
                
    WHEN (A.VDATE = @D1 AND A.MDATE  > @D2THEN (ABS(DATEDIFF(dd, @D2, @D1)))+1
                WHEN 
    (A.VDATE = @D1 AND A.MDATE = @D2THEN (ABS(DATEDIFF(dd, @D2, @D1)))
                
    WHEN (A.VDATE >= @D1 AND A.MDATE <= @D2THEN ABS(DATEDIFF(dd,A.MDATE,A.VDATE))
                
    WHEN (A.MDATE > @D2 AND (A.VDATE > @D1 AND A.VDATE <= @D2)) THEN ABS(DATEDIFF(dd, @D2,A.VDATE)) + 1
                WHEN 
    (A.VDATE < @D1 AND (A.MDATE < @D2 AND A.MDATE > @D1)) THEN ABS(DATEDIFF(ddA.MDATE,@D1))
                ELSE 
    0 END ) / (ABS(DATEDIFF(dd, @D1, @D2))+1),
           
    A.INTRATEINTPAID = CASE WHEN A.MDATE > @D2 THEN 0
                           WHEN A
    .MDATE <= @D2 AND A.MDATE < @D1 THEN 0
                              
    ELSE ABS(A.CCYAMT) * A.INTRATE * ((ABS(datediff(dd,A.MDATE,A.VDATE)))/365END ,
           
    INTSTATUS datediff(ddA.MDATE, @D2),
           
    ETERM = CASE WHEN (A.VDATE <= @D1 AND A.MDATE > @D2THEN (ABS(DATEDIFF(dd, @D2, @D1)))+1
                WHEN 
    (A.MDATE  = @D2 AND A.VDATE < @D1THEN ABS(DATEDIFF(ddA.MDATE, @D1))
                
    WHEN (A.VDATE = @D1 AND A.MDATE  > @D2THEN (ABS(DATEDIFF(dd, @D2, @D1)))+1
                WHEN 
    (A.VDATE = @D1 AND A.MDATE = @D2THEN (ABS(DATEDIFF(dd, @D2, @D1)))
                
    WHEN (A.VDATE >= @D1 AND A.MDATE <= @D2THEN ABS(DATEDIFF(dd,A.MDATE,A.VDATE))
                
    WHEN (A.MDATE > @D2 AND (A.VDATE > @D1 AND A.VDATE <= @D2)) THEN ABS(DATEDIFF(dd, @D2,A.VDATE)) + 1
                WHEN 
    (A.VDATE < @D1 AND (A.MDATE < @D2 AND A.MDATE > @D1)) THEN ABS(DATEDIFF(ddA.MDATE, @D1))
                ELSE 
    0 END,
           
    DIVISOR ABS(DATEDIFF(dd, @D1, @D2))+1B.CNOB.SNB.CCODEB.CA5
    FROM opicdldt
    .dbo.DLDT Aopicdldt.dbo.CUST B
    WHERE A
    .MDATE > @D1
          
    AND A.VERDATE <= @D2
          
    AND A.VDATE <= @D2
          
    AND (A.REVDATE > @D2 OR A.REVDATE IS NULL)
          AND 
    A.PRODTYPE 'PS'
          
    AND A.COST IN ('1300000000''1210000000''1510000000''1810000000''3020000000',
                     
    '1220000000''1530000000''1820000000''1840000000''1310000000',
                     
    '1520000000''1540000000''1830000000''3021000000')
          AND 
    A.CNO B.CNO 

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i don't write procedures in mysql, but shouldn't DECLARE $D1 be DECLARE @D1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •