Je veux vérifier la table PREMIUM_SERVICE_USER
si un enregistrement existe pour strClientID
mise à jour timeValid
pour +30 si aucun enregistrement pour strClientID
insertion à la table premium_service_user
.Vérifiez si l'enregistrement existe, si oui « mise à jour » sinon « insérer »
Qu'est-ce que je fais mal?
Il augmente timeValid
pendant +30 jours, mais insère également une autre ligne.
SELECT @pre_var = count(*)
FROM PREMIUM_SERVICE_USER
WHERE strClientID = @strClientID
/* bronze premium - 200 cash */
IF @Premium = 1
BEGIN
INSERT INTO PREMIUM_SERVICE_USER
(strClientID, timeReg, timeValid, bCurrent, durum)
VALUES
(@strClientID,getdate(),getdate() + 30,'1','1')
UPDATE TB_USER
SET cash = cash+200
WHERE strAccountID = @strClientID
END
IF @Premium = 1 AND @pre_var = 1
BEGIN
UPDATE PREMIUM_SERVICE_USER
SET timevalid = timevalid+30 where strClientID = @strClientID
UPDATE PREMIUM_SERVICE_USER
SET bCurrent = 1 where strClientID = @strClientID
UPDATE TB_USER
SET cash = cash+200 WHERE strAccountID = @strClientID
END
En plus de la solution trouvée ci-dessous, je suggère que vous combinez les instructions UPDATE en une seule déclaration pour PREMIUM_SERVICE_USER –