2

Este es mi query ...

DECLARE @fecha0 datetime
SET @fecha0 = (select top 1* 
    FROM events
    WHERE plate like '%D7Z716%' AND
        CONVERT(varchar, received, 103) = CONVERT(varchar, GETDATE(), 103) AND ADDRESS LIKE '%W BAYER%')

IF EXISTS(SELECT ISNULL(MIN(received),'') AS fecha 
    FROM events 
    WHERE plate LIKE '%D7Z716%'
        AND CONVERT(varchar,received,103)=CONVERT(varchar, GETDATE(), 103) AND ADDRESS LIKE '%W BAYER%')
BEGIN
    SELECT TOP(1) received 
    FROM events 
    WHERE received > @fecha0
END

El error que me sale.

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

3
  • This is SO en español. Please translate your question...
    – gbianchi
    Commented el 26 oct. 2018 a las 18:33
  • Espero estes bien Kevin, este sitio es Stack OverFlow en Español, te invito a que traduzcas tu pregunta. Saludos.
    – Rostan
    Commented el 26 oct. 2018 a las 18:34
  • oh sorry....... Commented el 26 oct. 2018 a las 18:41

1 respuesta 1

2

Tu inconveniente se encuentra en el primer subselect, al momento de cargar la variable @fecha0 no devuelve una columna en específico.

DECLARE @fecha0 datetime
SET @fecha0 = (SELECT TOP(1) * -- Aquí debes especificar la columna, no usar "*"
    FROM events
    WHERE plate like '%D7Z716%' AND
        CONVERT(varchar, received, 103) = CONVERT(varchar, GETDATE(), 103) 
        AND ADDRESS LIKE '%W BAYER%')

IF EXISTS(
    SELECT ISNULL(MIN(received),'')
    FROM events
    WHERE plate LIKE '%D7Z716%'
        AND CONVERT(varchar,received,103) = CONVERT(varchar, GETDATE(), 103) 
        AND ADDRESS LIKE '%W BAYER%'
)
BEGIN
    SELECT TOP(1) received 
    FROM events 
    WHERE received > @fecha0
END

Espero mi respuesta te haya ayudado.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.