Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   SQL-Statement: String to Int (https://www.delphipraxis.net/93321-sql-statement-string-int.html)

barnti 4. Jun 2007 12:45


SQL-Statement: String to Int
 
Hallo Forum,

ich möchte per ADODB eine Access-DB in einem Excelmakro abfragen:

Delphi-Quellcode:
Select
   Invoice.Kontaktaufkommen + ACQC.Kontaktaufkommen as Summe Kontaktaufkommen
FROM
...
Als Ergebnis bekomme ich zwei konkatenierte Strings, z.B.: 31 + 17 = 3117. Ich möchte aber die Summe der beiden Zahlen. Wie kann ich das in das Statement mitaufnehmen?

Danke für eure Aufmerksamkeit.

mkinzler 4. Jun 2007 12:46

Re: SQL-Statement: String to Int
 
Kennt access CAST()?

barnti 4. Jun 2007 13:19

Re: SQL-Statement: String to Int
 
Zitat:

Zitat von mkinzler
Kennt access CAST()?

Ich habe es mit CInt versucht:

Delphi-Quellcode:
"SELECT " _
                    & "[Zeit], " _
                    & "CInt(Invoice.Kontaktaufkommen) + CInt(ACQC.Kontaktaufkommen) As Kontaktaufkommen, " _
                    & "[AHT()] As AHT, " _
                    & " FROM customer ACQC, Invoice" _
                    & " WHERE Datum = '" & FCDate & "' "
Das scheint nicht zu klappen. Auch bei Cast meckert Excell...

hoika 4. Jun 2007 13:21

Re: SQL-Statement: String to Int
 
Hallo,

zeig doch mal das sql statement mit dem cast
und die "Meckermeldung" wäre auch nett


Heiko

mkinzler 4. Jun 2007 13:22

Re: SQL-Statement: String to Int
 
Es gäbe noch die Alternative, die Berechnung in VBA anstatt im SQL-Statement durchzuführen.

barnti 4. Jun 2007 14:01

Re: SQL-Statement: String to Int
 
Hi,

ehrlich gesagt ist mir nicht klar wie ich "Cast" benutze...

Mein Statement sieht jetzt so aus:

Delphi-Quellcode:
"SELECT " _
                    & " Invoice.Zeit, " _
                    & " Invoice.Kontaktaufkommen as IK, " _
                    & " Acquiredcustomer.Kontaktaufkommen as AK, " _
                    & " (CInt(Invoice.Kontaktaufkommen) + CInt(Acquiredcustomer.Kontaktaufkommen)) as Kontaktaufkommen " _
                    & " FROM Acquiredcustomer, Invoice" _
                    & " WHERE " _
                    & " Invoice.Zeit = Acquiredcustomer.Zeit" _
                    & " AND " _
                    & " Invoice.Datum = '" & FCDate & "' "
Danach bekomme ich folgende Werte:
IK: 10
AK: 16
Kontaktaufkommen: 26
Wobei in der Tabelle andere Werte stehen:
IK: 10
AK: 26

Das sollte also 36 für "Kontaktaufkommen" sein. Ich habe keine Ahnung warum diese Werte rauskommen...!? Kann mich jemand aufklären?

mkinzler 4. Jun 2007 14:03

Re: SQL-Statement: String to Int
 
SQL-Code:
select ... cast (<feld> as <Typ>) ...

barnti 4. Jun 2007 14:06

Re: SQL-Statement: String to Int
 
Mein Fehler. Es muss heißen:

Delphi-Quellcode:
"SELECT " _
                    & " Invoice.Zeit, " _
                    & " Invoice.Kontaktaufkommen as IK, " _
                    & " Acquiredcustomer.Kontaktaufkommen as AK, " _
                    & " (CInt(Invoice.Kontaktaufkommen) + CInt(Acquiredcustomer.Kontaktaufkommen)) as Kontaktaufkommen " _
                    & " FROM Acquiredcustomer, Invoice" _
                    & " WHERE " _
                    & " Invoice.Zeit = Acquiredcustomer.Zeit" _
                    & " AND " _
                    & " Invoice.Datum = '" & FCDate & "' " _
                    & " AND " _
                    & " Acquiredcustomer.Datum = '" & FCDate & "' "
Die zusätzliche Bedingung am Schluss liefert mir das Gewünschte! Danke für eure Aufmerksamkeit!

barnti 4. Jun 2007 14:07

Re: SQL-Statement: String to Int
 
Zitat:

Zitat von mkinzler
SQL-Code:
select ... cast (<feld> as <Typ>) ...

Danke für Deine Mühe. Ich habe mit CInt Erfolg gehabt!


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz