Quiero ver tabla PREMIUM_SERVICE_USER
si existe ningún registro de actualización strClientID
timeValid
de 30 si no hay registros para strClientID
inserción a premium_service_user
mesa.Compruebe si existe registro, si es así "actualización" si no "insertar"
¿Qué estoy haciendo mal?
Aumenta timeValid
durante +30 días pero también inserta otra fila.
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
Además de la solución que se encuentra debajo, también sugeriría que se combinan las instrucciones UPDATE en una sola declaración para PREMIUM_SERVICE_USER –