Guten Morgen,
es geht um eine SQL Server Prozedur und den Aufruf in ACCESS.
Hier der Aufruf in Access:
If isMonth = True Then
' was soll hier noch passieren?
' DoCmd.OpenQuery "ZV Provision -> 00 letzte Rechnung", acNormal, acEdit
If GetProvIsSpecial() Then
kindofProvValue = 5
lResIDValue = Forms![wPU -> Provisionen erstellen]!kmb_SpecialProv
Else
kindofProvValue = 1
End If
Else
kindofProvValue = 0
End If
' Open the connection
conn.Open
' Create a new command object
Set cmd = CreateObject("ADODB.Command")
' Set the command properties
With cmd
cmd.CommandTimeout = 1000 ' Um TimeOutfehler zu umngehen
.ActiveConnection = conn
.CommandType = 4 ' adCmdStoredProc
.CommandText = "PrepairProvision"
End With
' parameter objects
' Set parameter = command.CreateParameter (Name, Type, Direction, Size, Value)
Set param1 = cmd.CreateParameter("@DateFrom", 7, 1, , DateValue(dBegin))
Set param2 = cmd.CreateParameter("@DateTo", 7, 1, , DateValue(dEnd))
Set kindofProvi = cmd.CreateParameter("@ProviKind", 16, 1, , kindofProvValue)
Set lResID = cmd.CreateParameter("@SpzProvi", 16, 1, , lResIDValue)
' parameters to the command
cmd.Parameters.Append param1
cmd.Parameters.Append param2
cmd.Parameters.Append kindofProvi
cmd.Parameters.Append lResID
' cmd.Parameters.Value = kindofProvValue
' Execute
cmd.Execute
und Hier der Teil der SQL Server Prozedur, der nicht richtig angesprochen wird...
USE [FENG]
GO
/****** Object: StoredProcedure [dbo].[PrepairProvision] Script Date: 18.11.2024 09:35:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PrepairProvision]
@DateFrom datetime,
@DateTo datetime,
@ProviKind as int,
@SpzProvi as int
AS
SET NOCOUNT ON;
SET ANSI_WARNINGS OFF;
-- Wir benötigen hier eine Zwischentabelle da es in SQL Server kein DISTINTROW gibt
-- Daher erst => [zzHilfstabelle->Prov LastProv1]
-- dann => [zzHilfstabelle->Prov LastProv]
DELETE FROM dbo.[zzHilfstabelle->Prov LastProv1]
DELETE FROM dbo.[zzHilfstabelle->Prov LastProv]
DELETE FROM dbo.[zzHilfstabelle->ProvAnzTerm]
DELETE FROM dbo.[zzHilfstabelle->Prov Reseller]
DELETE FROM [zzHilfstabelle->Provision]
DELETE FROM [zzHilfstabelle->ProvAnzTerm]
-- Es fehlt der Teil, der angeblich die EC Provisonen zusammensucht, die berücksichtigen wir aber nicht mehr
-- Welche Art Provisioen soll erstellt werden, monatli, Quartal
--set @ProviKind= 0 --|| @ProviKind=0 ?
if @ProviKind=0
begin
INSERT INTO [zzHilfstabelle->Prov LastProv1] ( RESELLER_ID, isGWK,monatliche, RESELLER_PROVMONTH, HVs, RESELLER_ISHV, [Last], Angelegt, bis, RESELLER_SHORT )
SELECT DISTINCT RESELLER.RESELLER_ID, 0 AS isGWK, @ProviKind as monatliche, RESELLER.RESELLER_PROVMONTH, 0 AS HVs, RESELLER.RESELLER_ISHV,
Max(
IIf([PROVAB_DATE] IS NUll,
IIf([RESELLER_ProvFrom]IS Null,
IIf([RESELLER_WHENNEW] IS Null Or ([RESELLER_WHENNEW] < CAST(CONCAT('31.12.' , Year(Getdate())-5 )AS DATE)),CAST(CONCAT('31.12.' , Year(Getdate())-5 ) AS DATE),
[RESELLER_WHENNEW]
),[RESELLER_ProvFrom]
),[PROVAB_DATE])
)AS [Last],
Min(IIf(([RESELLER_WHENNEW]IS NULL),CAST('01.01.2000' AS Date),[RESELLER_WHENNEW])) AS Angelegt,
@DateTo AS bis, RESELLER.RESELLER_SHORT
FROM data.RESELLER LEFT JOIN [ZV Provision -> 00 letzte Rechnung hilf] ON RESELLER.RESELLER_ID = [ZV Provision -> 00 letzte Rechnung hilf].RESELLER_ID
WHERE (RESELLER.RESELLER_PAYPROVI=1)
AND (RESELLER.RESELLER_PROVMONTH=0
AND (RESELLER.RESELLER_ISHV=0))
GROUP BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV, RESELLER.RESELLER_SHORT,[RESELLER_WHENNEW],RESELLER_ProvFrom
HAVING (((RESELLER.RESELLER_ID)<>11))
end
else if @ProviKind=5
begin
INSERT INTO [zzHilfstabelle->Prov LastProv1] ( RESELLER_ID, isGWK,monatliche, RESELLER_PROVMONTH, HVs, RESELLER_ISHV, [Last], Angelegt, bis, RESELLER_SHORT )
SELECT DISTINCT RESELLER.RESELLER_ID, 0 AS isGWK, @ProviKind as monatliche , RESELLER.RESELLER_PROVMONTH,
0 AS HVs, RESELLER.RESELLER_ISHV,
Max(
IIf([PROVAB_DATE] IS NUll,
IIf([RESELLER_ProvFrom]IS Null,
IIf([RESELLER_WHENNEW] IS Null Or ([RESELLER_WHENNEW] < CAST(CONCAT('31.12.' , Year(Getdate())-5 )AS DATE)),CAST(CONCAT('31.12.' , Year(Getdate())-5 ) AS DATE),
[RESELLER_WHENNEW]
),[RESELLER_ProvFrom]
),[PROVAB_DATE])
)AS [Last],
Min(IIf(([RESELLER_WHENNEW]IS NULL),CAST('01.01.2000' AS Date),[RESELLER_WHENNEW])) AS Angelegt,
@DateTo AS bis, RESELLER.RESELLER_SHORT
FROM data.RESELLER LEFT JOIN [ZV Provision -> 00 letzte Rechnung hilf] ON RESELLER.RESELLER_ID = [ZV Provision -> 00 letzte Rechnung hilf].RESELLER_ID
WHERE RESELLER.RESELLER_PAYPROVI=1
GROUP BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV, RESELLER.RESELLER_SHORT
HAVING (((RESELLER.RESELLER_ID)=@SpzProvi))
ORDER BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV,
RESELLER.RESELLER_SHORT DESC;
end
else
begin
---INSERT INTO [zzHilfstabelle->Prov LastProv1]()
INSERT INTO [zzHilfstabelle->Prov LastProv1] ( RESELLER_ID, isGWK,monatliche, RESELLER_PROVMONTH, HVs, RESELLER_ISHV, [Last], Angelegt, bis, RESELLER_SHORT )
SELECT DISTINCT RESELLER.RESELLER_ID, 0 as isGWK, @ProviKind AS monatliche, RESELLER.RESELLER_PROVMONTH, 0 AS HVs, RESELLER.RESELLER_ISHV,
Max(
IIf([PROVAB_DATE] IS NUll,
IIf([RESELLER_ProvFrom]IS Null,
IIf([RESELLER_WHENNEW] IS Null Or ([RESELLER_WHENNEW] < CAST(CONCAT('31.12.' , Year(Getdate())-5 )AS DATE)),CAST(CONCAT('31.12.' , Year(Getdate())-5 ) AS DATE),
[RESELLER_WHENNEW]
),[RESELLER_ProvFrom]
),[PROVAB_DATE])
)AS [Last],
Min(IIf(([RESELLER_WHENNEW]IS NULL),CAST('01.01.2000' AS Date),[RESELLER_WHENNEW])) AS Angelegt,
@DateTo AS bis, RESELLER.RESELLER_SHORT
FROM data.RESELLER LEFT JOIN [ZV Provision -> 00 letzte Rechnung hilf] ON RESELLER.RESELLER_ID = [ZV Provision -> 00 letzte Rechnung hilf].RESELLER_ID
WHERE ( (RESELLER.RESELLER_PAYPROVI=1)
AND RESELLER.RESELLER_PROVMONTH= 1
)
AND RESELLER.RESELLER_ISHV=0
GROUP BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV,RESELLER.RESELLER_SHORT
HAVING RESELLER.RESELLER_ID<>11
ORDER BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV,
RESELLER.RESELLER_SHORT DESC;
end
Ich hoffe das ist jetzt nicht zuviel Code und damit zu unübersichtlich. Ich weiß nur soviel, wenn
kindofProvValue = 1
oder kindofProvValue = 0
dann läuft alles. Wenn ich den Wert 5 übergebe, dann bejkomme ich kein Ergebnis, als wenn bei der If- else Anweisung was nicht greift.
Ein Ergebnis bekommt man, da ich den Teil für sich in einem neuen SQL Editor ausgeführt habe um zu kontrollieren.
es geht um eine SQL Server Prozedur und den Aufruf in ACCESS.
Hier der Aufruf in Access:
If isMonth = True Then
' was soll hier noch passieren?
' DoCmd.OpenQuery "ZV Provision -> 00 letzte Rechnung", acNormal, acEdit
If GetProvIsSpecial() Then
kindofProvValue = 5
lResIDValue = Forms![wPU -> Provisionen erstellen]!kmb_SpecialProv
Else
kindofProvValue = 1
End If
Else
kindofProvValue = 0
End If
' Open the connection
conn.Open
' Create a new command object
Set cmd = CreateObject("ADODB.Command")
' Set the command properties
With cmd
cmd.CommandTimeout = 1000 ' Um TimeOutfehler zu umngehen
.ActiveConnection = conn
.CommandType = 4 ' adCmdStoredProc
.CommandText = "PrepairProvision"
End With
' parameter objects
' Set parameter = command.CreateParameter (Name, Type, Direction, Size, Value)
Set param1 = cmd.CreateParameter("@DateFrom", 7, 1, , DateValue(dBegin))
Set param2 = cmd.CreateParameter("@DateTo", 7, 1, , DateValue(dEnd))
Set kindofProvi = cmd.CreateParameter("@ProviKind", 16, 1, , kindofProvValue)
Set lResID = cmd.CreateParameter("@SpzProvi", 16, 1, , lResIDValue)
' parameters to the command
cmd.Parameters.Append param1
cmd.Parameters.Append param2
cmd.Parameters.Append kindofProvi
cmd.Parameters.Append lResID
' cmd.Parameters.Value = kindofProvValue
' Execute
cmd.Execute
und Hier der Teil der SQL Server Prozedur, der nicht richtig angesprochen wird...
USE [FENG]
GO
/****** Object: StoredProcedure [dbo].[PrepairProvision] Script Date: 18.11.2024 09:35:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PrepairProvision]
@DateFrom datetime,
@DateTo datetime,
@ProviKind as int,
@SpzProvi as int
AS
SET NOCOUNT ON;
SET ANSI_WARNINGS OFF;
-- Wir benötigen hier eine Zwischentabelle da es in SQL Server kein DISTINTROW gibt
-- Daher erst => [zzHilfstabelle->Prov LastProv1]
-- dann => [zzHilfstabelle->Prov LastProv]
DELETE FROM dbo.[zzHilfstabelle->Prov LastProv1]
DELETE FROM dbo.[zzHilfstabelle->Prov LastProv]
DELETE FROM dbo.[zzHilfstabelle->ProvAnzTerm]
DELETE FROM dbo.[zzHilfstabelle->Prov Reseller]
DELETE FROM [zzHilfstabelle->Provision]
DELETE FROM [zzHilfstabelle->ProvAnzTerm]
-- Es fehlt der Teil, der angeblich die EC Provisonen zusammensucht, die berücksichtigen wir aber nicht mehr
-- Welche Art Provisioen soll erstellt werden, monatli, Quartal
--set @ProviKind= 0 --|| @ProviKind=0 ?
if @ProviKind=0
begin
INSERT INTO [zzHilfstabelle->Prov LastProv1] ( RESELLER_ID, isGWK,monatliche, RESELLER_PROVMONTH, HVs, RESELLER_ISHV, [Last], Angelegt, bis, RESELLER_SHORT )
SELECT DISTINCT RESELLER.RESELLER_ID, 0 AS isGWK, @ProviKind as monatliche, RESELLER.RESELLER_PROVMONTH, 0 AS HVs, RESELLER.RESELLER_ISHV,
Max(
IIf([PROVAB_DATE] IS NUll,
IIf([RESELLER_ProvFrom]IS Null,
IIf([RESELLER_WHENNEW] IS Null Or ([RESELLER_WHENNEW] < CAST(CONCAT('31.12.' , Year(Getdate())-5 )AS DATE)),CAST(CONCAT('31.12.' , Year(Getdate())-5 ) AS DATE),
[RESELLER_WHENNEW]
),[RESELLER_ProvFrom]
),[PROVAB_DATE])
)AS [Last],
Min(IIf(([RESELLER_WHENNEW]IS NULL),CAST('01.01.2000' AS Date),[RESELLER_WHENNEW])) AS Angelegt,
@DateTo AS bis, RESELLER.RESELLER_SHORT
FROM data.RESELLER LEFT JOIN [ZV Provision -> 00 letzte Rechnung hilf] ON RESELLER.RESELLER_ID = [ZV Provision -> 00 letzte Rechnung hilf].RESELLER_ID
WHERE (RESELLER.RESELLER_PAYPROVI=1)
AND (RESELLER.RESELLER_PROVMONTH=0
AND (RESELLER.RESELLER_ISHV=0))
GROUP BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV, RESELLER.RESELLER_SHORT,[RESELLER_WHENNEW],RESELLER_ProvFrom
HAVING (((RESELLER.RESELLER_ID)<>11))
end
else if @ProviKind=5
begin
INSERT INTO [zzHilfstabelle->Prov LastProv1] ( RESELLER_ID, isGWK,monatliche, RESELLER_PROVMONTH, HVs, RESELLER_ISHV, [Last], Angelegt, bis, RESELLER_SHORT )
SELECT DISTINCT RESELLER.RESELLER_ID, 0 AS isGWK, @ProviKind as monatliche , RESELLER.RESELLER_PROVMONTH,
0 AS HVs, RESELLER.RESELLER_ISHV,
Max(
IIf([PROVAB_DATE] IS NUll,
IIf([RESELLER_ProvFrom]IS Null,
IIf([RESELLER_WHENNEW] IS Null Or ([RESELLER_WHENNEW] < CAST(CONCAT('31.12.' , Year(Getdate())-5 )AS DATE)),CAST(CONCAT('31.12.' , Year(Getdate())-5 ) AS DATE),
[RESELLER_WHENNEW]
),[RESELLER_ProvFrom]
),[PROVAB_DATE])
)AS [Last],
Min(IIf(([RESELLER_WHENNEW]IS NULL),CAST('01.01.2000' AS Date),[RESELLER_WHENNEW])) AS Angelegt,
@DateTo AS bis, RESELLER.RESELLER_SHORT
FROM data.RESELLER LEFT JOIN [ZV Provision -> 00 letzte Rechnung hilf] ON RESELLER.RESELLER_ID = [ZV Provision -> 00 letzte Rechnung hilf].RESELLER_ID
WHERE RESELLER.RESELLER_PAYPROVI=1
GROUP BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV, RESELLER.RESELLER_SHORT
HAVING (((RESELLER.RESELLER_ID)=@SpzProvi))
ORDER BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV,
RESELLER.RESELLER_SHORT DESC;
end
else
begin
---INSERT INTO [zzHilfstabelle->Prov LastProv1]()
INSERT INTO [zzHilfstabelle->Prov LastProv1] ( RESELLER_ID, isGWK,monatliche, RESELLER_PROVMONTH, HVs, RESELLER_ISHV, [Last], Angelegt, bis, RESELLER_SHORT )
SELECT DISTINCT RESELLER.RESELLER_ID, 0 as isGWK, @ProviKind AS monatliche, RESELLER.RESELLER_PROVMONTH, 0 AS HVs, RESELLER.RESELLER_ISHV,
Max(
IIf([PROVAB_DATE] IS NUll,
IIf([RESELLER_ProvFrom]IS Null,
IIf([RESELLER_WHENNEW] IS Null Or ([RESELLER_WHENNEW] < CAST(CONCAT('31.12.' , Year(Getdate())-5 )AS DATE)),CAST(CONCAT('31.12.' , Year(Getdate())-5 ) AS DATE),
[RESELLER_WHENNEW]
),[RESELLER_ProvFrom]
),[PROVAB_DATE])
)AS [Last],
Min(IIf(([RESELLER_WHENNEW]IS NULL),CAST('01.01.2000' AS Date),[RESELLER_WHENNEW])) AS Angelegt,
@DateTo AS bis, RESELLER.RESELLER_SHORT
FROM data.RESELLER LEFT JOIN [ZV Provision -> 00 letzte Rechnung hilf] ON RESELLER.RESELLER_ID = [ZV Provision -> 00 letzte Rechnung hilf].RESELLER_ID
WHERE ( (RESELLER.RESELLER_PAYPROVI=1)
AND RESELLER.RESELLER_PROVMONTH= 1
)
AND RESELLER.RESELLER_ISHV=0
GROUP BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV,RESELLER.RESELLER_SHORT
HAVING RESELLER.RESELLER_ID<>11
ORDER BY RESELLER.RESELLER_ID, RESELLER.RESELLER_PROVMONTH, RESELLER.RESELLER_ISHV,
RESELLER.RESELLER_SHORT DESC;
end
Ich hoffe das ist jetzt nicht zuviel Code und damit zu unübersichtlich. Ich weiß nur soviel, wenn
kindofProvValue = 1
oder kindofProvValue = 0
dann läuft alles. Wenn ich den Wert 5 übergebe, dann bejkomme ich kein Ergebnis, als wenn bei der If- else Anweisung was nicht greift.
Ein Ergebnis bekommt man, da ich den Teil für sich in einem neuen SQL Editor ausgeführt habe um zu kontrollieren.