Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

MSSQL - StoredProcedure mit XML und IF

Empfohlene Antworten

Veröffentlicht

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

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]

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.