Zum Inhalt springen

Empfohlene Beiträge

Geschrieben

Hallo zusammen,

ich habe folgenden rießen SQL und folgende Fehlermeldung:

Fehlermeldung:

Unzulässiges einklammern des Namens 'select '1' as Sortierung, Firma ...'


SELECT Firma, Zielrufnummer, Datum, Uhrzeit, Nebenstelle, Standardpreis, Bonuspreis

FROM [select '1' as Sortierung, Firma,Nebenstelle, Datum, Uhrzeit, Standardpreis, Bonuspreis, Zielrufnummer from (


select 

    ( select round(sum(evn.[Dauer/Sek])/60) from evn) AS Gesamtzeit,

    'Geopost'  as Firma,

    evn.Nebenstelle, evn.Datum, evn.Uhrzeit, 

     evn.[Dauer/Sek] as Dauer, 

     iif(Gesamtzeit < 1755000,round(((evn.[Dauer/Sek] / 60)* tarif.Malus), 4),0) as Maluspreis,

     iif(Gesamtzeit <= 2145000 AND Gesamtzeit > 1755000,round(((evn.[Dauer/Sek] / 60)* tarif.Standard), 4),0) as Standardpreis,

     iif (Gesamtzeit > 2145000, round(((evn.[Dauer/Sek] / 60)* tarif.Bonus), 4), 0) as Bonuspreis, 

    evn.Zielrufnummer

    FROM evn,tarif,vpn where evn.artikelnr = tarif.artikelnr and vpn.tel2 = '4925' and evn.fkto = vpn.fkto and  instr(';7258;7274;7253;7266;7249;7251;7252;'+

'7001;7009;7011;7091;7071;7081;7031;7041;7043;7051;7068;7021;7066;7022;7016;7065;7061;7005;7013;7011;',';' +evn.Nebenstelle+ ';') ) as Unterselect1

union

select '1.1' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect

union

select '1.2' as Sortierung, FirmaGesamt, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, Malusgesamtpreis, Standardgesamtpreis, Bonusgesamtpreis, '' As Zielrufnummer from (


SELECT '', 'Geopost-Gesamt' as FirmaGesamt , '', '',

( select round(sum(evn.[Dauer/Sek])/60) from evn) AS Gesamtzeit,

     iif( Firma = 'Delicom', 497, 0) as Grundgebuehr,

iif(Gesamtzeit < 1755000,round(((sum(Dauer*maluspreis)/60) +Grundgebuehr),2),0) AS Malusgesamtpreis,     

iif(Gesamtzeit <= 2145000 AND Gesamtzeit > 1755000,round(((sum(Dauer*standardpreis)/60) +Grundgebuehr),2),0) AS Standardgesamtpreis, 

iif (Gesamtzeit > 2145000, round(((sum(Dauer*bonuspreis)/60) + Grundgebuehr),2),0) AS Bonusgesamtpreis, ''

FROM (



select 

    'Geopost'  as Firma,

     evn.[Dauer/Sek] as Dauer, tarif.Malus as maluspreis, tarif.Standard as standardpreis, tarif.Bonus as bonuspreis

    FROM evn,tarif,vpn where evn.artikelnr = tarif.artikelnr and vpn.tel2 = '4925' and evn.fkto = vpn.fkto and  instr(';7258;7274;7253;7266;7249;7251;7252;'+

'7001;7009;7011;7091;7071;7081;7031;7041;7043;7051;7068;7021;7066;7022;7016;7065;7061;7005;7013;7011;',';' +evn.Nebenstelle+ ';'))  AS Unterselect GROUP BY firma) as Unterselect2



union

select '1.3' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect

union

select '1.3.1' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect



union

select '2' as Sortierung, Firma,Nebenstelle, Datum, Uhrzeit, Maluspreis, Standardpreis, Bonuspreis, Zielrufnummer from (


select 

    ( select round(sum(evn.[Dauer/Sek])/60) from evn) AS Gesamtzeit,

    'GmbH' as Firma, evn.Nebenstelle, evn.Datum, evn.Uhrzeit, 

     evn.[Dauer/Sek] as Dauer, 

     iif(Gesamtzeit < 1755000,round(((evn.[Dauer/Sek] / 60)* tarif.Malus), 4),0) as Maluspreis,

     iif(Gesamtzeit <= 2145000 AND Gesamtzeit > 1755000,round(((evn.[Dauer/Sek] / 60)* tarif.Standard), 4),0) as Standardpreis,

     iif (Gesamtzeit > 2145000, round(((evn.[Dauer/Sek] / 60)* tarif.Bonus), 4), 0) as Bonuspreis, 

    evn.Zielrufnummer

    FROM evn,tarif,vpn where evn.artikelnr = tarif.artikelnr and vpn.tel2 = '4925' and evn.fkto = vpn.fkto and  instr(';6015;6017;6018;6021;6012;6014;6007;6011;6054;6019;6020;',';' +evn.Nebenstelle+ ';') ) as Unterselect1


union

select '2.1' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis,, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect

union

select '2.2' as Sortierung,  FirmaGesamt, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, Malusgesamtpreis, Standardgesamtpreis, Bonusgesamtpreis, '' As Zielrufnummer from (


SELECT '', 'GmbH-Gesamt' as FirmaGesamt, '', '',

( select round(sum(evn.[Dauer/Sek])/60) from evn) AS Gesamtzeit,

     iif( Firma = 'Delicom', 497, 0) as Grundgebuehr,

iif(Gesamtzeit < 1755000,round(((sum(Dauer*maluspreis)/60) +Grundgebuehr),2),0) AS Malusgesamtpreis, 

iif(Gesamtzeit <= 2145000 AND Gesamtzeit > 1755000,round(((sum(Dauer*standardpreis)/60) +Grundgebuehr),2),0) AS Standardgesamtpreis, 

iif (Gesamtzeit > 2145000, round(((sum(Dauer*bonuspreis)/60) + Grundgebuehr),2),0) AS Bonusgesamtpreis, ''

FROM (


select 

     'GmbH' as Firma,

     evn.[Dauer/Sek] as Dauer, tarif.Malus as maluspreis, tarif.Standard as standardpreis, tarif.Bonus as bonuspreis

    FROM evn,tarif,vpn where evn.artikelnr = tarif.artikelnr and vpn.tel2 = '4925' and evn.fkto = vpn.fkto and  instr(';6015;6017;6018;6021;6012;6014;6007;6011;6054;6019;6020;',';' +evn.Nebenstelle+ ';'))  AS Unterselect  GROUP BY firma) as Unterselect2


union


select '2.3' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect

union

select '2.3.1' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, , '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect


union


select '3' as Sortierung, Firma,Nebenstelle, Datum, Uhrzeit, Maluspreis, Standardpreis, Bonuspreis, Zielrufnummer from (

select 

    ( select round(sum(evn.[Dauer/Sek])/60) from evn) AS Gesamtzeit,

      'Delicom' as Firma, evn.Nebenstelle, evn.Datum, evn.Uhrzeit, 

     evn.[Dauer/Sek] as Dauer, 

     iif(Gesamtzeit < 1755000,round(((evn.[Dauer/Sek] / 60)* tarif.Malus), 4),0) as Maluspreis,

     iif(Gesamtzeit <= 2145000 AND Gesamtzeit > 1755000,round(((evn.[Dauer/Sek] / 60)* tarif.Standard), 4),0) as Standardpreis,

     iif (Gesamtzeit > 2145000, round(((evn.[Dauer/Sek] / 60)* tarif.Bonus), 4), 0) as Bonuspreis, 

    evn.Zielrufnummer

    FROM evn,tarif,vpn where evn.artikelnr = tarif.artikelnr and vpn.tel2 = '4925' and evn.fkto = vpn.fkto

 and not  instr(';7258;7274;7253;7266;7249;7251;7252;'+

'7001;7009;7011;7091;7071;7081;7031;7041;7043;7051;7068;7021;7066;7022;7016;7065;7061;7005;7013;7011;6015;6017;6018;6021;6012;6014;6007;6011;6054;6019;6020;',';' +evn.Nebenstelle+ ';') 

) as Unterselect1


where firma = 'Delicom'

union

select '3.1' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect

union

select '3.2' as Sortierung, FirmaGesamt, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, Malusgesamtpreis, Standardgesamtpreis, Bonusgesamtpreis, '' As Zielrufnummer from (


SELECT '', 'Delicom-Gesamt' as FirmaGesamt, '', '',

( select round(sum(evn.[Dauer/Sek])/60) from evn) AS Gesamtzeit,

     iif( Firma = 'Delicom', 497, 0) as Grundgebuehr,

iif(Gesamtzeit < 1755000,round(((sum(Dauer*maluspreis)/60) +Grundgebuehr),2),0) AS Malusgesamtpreis, 

iif(Gesamtzeit <= 2145000 AND Gesamtzeit > 1755000,round(((sum(Dauer*standardpreis)/60) +Grundgebuehr),2),0) AS Standardgesamtpreis, 

iif (Gesamtzeit > 2145000, round(((sum(Dauer*bonuspreis)/60) + Grundgebuehr),2),0) AS Bonusgesamtpreis, ''

FROM (



select 

     'Delicom' as Firma,

     evn.[Dauer/Sek] as Dauer, tarif.Malus as maluspreis, tarif.Standard as standardpreis, tarif.Bonus as bonuspreis

    FROM evn,tarif,vpn where evn.artikelnr = tarif.artikelnr and vpn.tel2 = '4925' and evn.fkto = vpn.fkto

and not  instr(';7258;7274;7253;7266;7249;7251;7252;'+

'7001;7009;7011;7091;7071;7081;7031;7041;7043;7051;7068;7021;7066;7022;7016;7065;7061;7005;7013;7011;6015;6017;6018;6021;6012;6014;6007;6011;6054;6019;6020;',';' +evn.Nebenstelle+ ';'))  AS Unterselect GROUP BY firma) as Unterselect2


union

select '3.3' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect

union

select '3.3.1' as Sortierung, '' As Firma, '' As Nebenstelle, '' As Datum, '' As Uhrzeit, '' As Maluspreis, '' As Standardpreis, '' As Bonuspreis, '' As Zielrufnummer from (

select min(1) from evn where 1 = 2) as tempselect

]. AS Hauptselect;

Kann mir jmd helfen?

Geschrieben

Du musst dir schon erstmal selbst Muehe geben und zumindest die Unions aufloesen. Dann ist das Ganze nicht mehr so gross und du findest den Fehler auch selbst ganz leich (vermute ich).

Goos

Geschrieben
Du musst dir schon erstmal selbst Muehe geben und zumindest die Unions aufloesen. Dann ist das Ganze nicht mehr so gross und du findest den Fehler auch selbst ganz leich (vermute ich).

Goos

wie kann ich ein union auflösen?

kannst du mir das an nem kleinen beispiel erläutern?

Geschrieben

Na du hast zwischen den ganzen Unions lauter einzelne Selects, die ansich auch alle einzeln funktionieren sollten. Also kannst der Reihe nach immer ein Select Statement rauskopieren und testen. So hast die Moeglichkeit, einen Fehler in einem davon zu entdecken.

Goos

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...