'Perl Script: SQL commands with IF are displayed as syntax errors

SQL commands with IF which are working in MySQL DB are displayed as syntax errors.

if (exists(
    SELECT * FROM tanss.leistungen
    where
    firmenid = Tanss
    and date(FROM_UNIXTIME(datum)) >= DATE_ADD(DATE_ADD(MAKEDATE(YEAR(CURRENT_DATE), 1), INTERVAL MONTH(CURRENT_DATE)-6 MONTH), INTERVAL -0 DAY)
    and date(FROM_UNIXTIME(datum)) < DATE_ADD(DATE_ADD(MAKEDATE(YEAR(CURRENT_DATE), 1), INTERVAL MONTH(CURRENT_DATE) MONTH), INTERVAL -0 DAY)
) =0 ,"ohne","vorhanden") as Leistung

or more simple such as

if(niederlassung.name is null,"Niederlassung Warendorf",niederlassung.name) as Niederlassung

Error output of cmd is:

Bareword found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 123, near ") =0 ,"ohne" (Might be a runaway multi-line "" string starting on line 115) (Missing operator before ohne?) String found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 123, near "ohne","" Bareword found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 123, near "","vorhanden" (Missing operator before vorhanden?) String found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 123, near "left join tanss.anfahrtpauschale_preise as anfahrtfirma on anfahrtfirma.linkID = vertrag.id and anfahrtfirma.zoneID = "" (Missing semicolon on previous line?)

or

Bareword found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 115, near "if(niederlassung.name is null,"Niederlassung" (Might be a runaway multi-line "" string starting on line 111) (Do you need to predeclare if?)

Im using DBD::ODBC

Is there any way that Perl can accept such extended SQL commands without me having to edit it in the script, like im currently doing?

update:

  • the SQL is a string and the full statement has quotation around it
  • the SQL statement is 100% working

main part of code (but still not full code):

    sub getLeadingMethode{
    $SQL = "
    SELECT
        vertrag.ID as VertragsDBid,
        vertrag.name as Vertragsart,
        vertrag.datumvon as von,
        vertrag.datumbis as bis,
        firmen.displayID as Tanss,
        firmen.name as Kundenname,
    if (exists(
            SELECT * FROM tanss.leistungen
            where
            firmenid = Tanss
            and date(FROM_UNIXTIME(datum)) >= DATE_ADD(DATE_ADD(MAKEDATE(YEAR(CURRENT_DATE), 1), INTERVAL MONTH(CURRENT_DATE)-6 MONTH), INTERVAL -0 DAY)
            and date(FROM_UNIXTIME(datum)) < DATE_ADD(DATE_ADD(MAKEDATE(YEAR(CURRENT_DATE), 1), INTERVAL MONTH(CURRENT_DATE) MONTH), INTERVAL -0 DAY)
        ) =0 ,"$4","$5") as Leistung

    FROM tanss.vertrag
        left join tanss.firmen on tanss.firmen.ID = vertrag.firmenID
        left join tanss.anfahrtpauschale_preise as anfahrtfirma on anfahrtfirma.linkID = vertrag.id and anfahrtfirma.zoneID = "$6" and anfahrtfirma.linktypid = "$7"
        left join (select * from tanss.firmen_fahrt as fahrt_1 where km_einfach =(select min(km_einfach) from tanss.firmen_fahrt where firmenID = fahrt_1.firmenid) ) as anfahrt on anfahrt.firmenID = firmen.id
        left join tanss.firmen as niederlassung on niederlassung.id = anfahrt.mandantID
        left join tanss.f_info_werte as vb on vb.firmenid = firmen.id and defID = "$8";";

Full error message:

C:\Entwicklung\LWEI_SampleCodes>sampleCode20.pl
Scalar found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 115, near ") =0 ,"$4"
  (Might be a runaway multi-line "" string starting on line 100)
        (Missing operator before $4?)
String found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 115, near "$4",""
        (Missing operator before ","?)
Scalar found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 115, near "","$5"
        (Missing operator before $5?)
String found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 115, near "left join tanss.anfahrtpauschale_preise as anfahrtfirma on anfahrtfirma.linkID = vertrag.id and anfahrtfirma.zoneID = ""
        (Missing semicolon on previous line?)
Scalar found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 119, near "left join tanss.anfahrtpauschale_preise as anfahrtfirma on anfahrtfirma.linkID = vertrag.id and anfahrtfirma.zoneID = "$6"
  (Might be a runaway multi-line "" string starting on line 115)
        (Do you need to predeclare left?)
String found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 119, near "$6" and anfahrtfirma.linktypid = ""
        (Missing operator before " and anfahrtfirma.linktypid = "?)
Scalar found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 119, near "" and anfahrtfirma.linktypid = "$7"
        (Missing operator before $7?)
String found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 119, near "left join tanss.f_info_werte as vb on vb.firmenid = firmen.id and defID = ""
        (Missing semicolon on previous line?)
Scalar found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 122, near "left join tanss.f_info_werte as vb on vb.firmenid = firmen.id and defID = "$8"
  (Might be a runaway multi-line "" string starting on line 119)
        (Do you need to predeclare left?)
String found where operator expected at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 122, near """
        (Missing semicolon on previous line?)
syntax error at C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl line 115, near ") =0 ,"$4"
Execution of C:\Entwicklung\LWEI_SampleCodes\sampleCode20.pl aborted due to compilation errors.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source