Zum Inhalt springen

Empfohlene Beiträge

Geschrieben

Hallo zusammen,

hab bei einem SP ein Problem.

Mein SP bekommt als Parameter ein XML mit allen Werten. Der SP muss eine Tabelle Update, allerdings mit der Bedingung, wenn das übergebene Datum kleiner als heute ist, muss eine zusätzlich Spalte (Status) upgedatet werden.

Frage: Wie mache ich des mit IF und den Zugriff auf XML Werte?


DECLARE @idoc INT

EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlData


UPDATE tbContracts

SET

	Price = XMLp.Price,

	ContractBegin = XMLp.BeginDate,

	ContractEnd = XMLp.EndDate


FROM

	OPENXML(@idoc, '/ROOT/Contract')

		WITH (

			ContractID	int,

			BeginDate	smalldatetime,

			EndDate		smalldatetime,

			Price		money					

		) XMLp


WHERE (ID=XMLp.ContractID)


IF (XMLp.EndDate < GetDate())

BEGIN

	UPDATE tbContracts SET StatusID=2 WHERE (ID=XMLp.ContractID)

END

EXEC sp_xml_removedocument @idoc

Lasse ich den IF Block weg, funktioniert mein SP, sonst gibts Probleme beim ausführen auf die DB.

Danke

Gruß

Antibiotik

Geschrieben

Vielleicht so?

DECLARE @idoc INT
EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlData
GO
EXEC 'UPDATE tbContracts
SET
Price ='+ XMLp.Price+',
ContractBegin ='+ XMLp.BeginDate+',
ContractEnd ='+ XMLp.EndDate+', '+
IF (XMLp.EndDate < GetDate())+
'StatusID=2 ' +
End IF+

'FROM
OPENXML('+@idoc+', '/ROOT/Contract')
WITH (
ContractID int,
BeginDate smalldatetime,
EndDate smalldatetime,
Price money
) XMLp

WHERE (ID='+XMLp.ContractID+')'
GO


EXEC sp_xml_removedocument @idoc[/PHP]

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...