I want to display a value according to the current date

Asked

Viewed 52 times

0

I want to select the amount of Num_CP according to the current date, so I am using the function GETDATE(), but my SQL points out the following error:

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

My Code:

BEGIN   
    SET NOCOUNT ON;

--DECLARE @DM3 DATETIME;

 SET @D0 = (SELECT DATEADD(day, 0, GETDATE()) AS D0, COUNT(NUM_CP) AS QUANTIDADE_CPS FROM VW_Vendas);                        


 SELECT CONVERT(VARCHAR, '-')'RESULTADO',
        (
        SELECT @D0 AS DATA_ATUAL FROM VW_Vendas VW0 WHERE VW0.SITUACAO_RECADO IS NOT NULL
        AND VW0.SITUACAO_RECADO LIKE '%Aguardando Aprovação Cliente%' AND
        VW0.DT_CRIACAO = GETDATE()
        )'DATAS DIA ZERO'


END
GO

1 answer

0

In free translation your mistake is as follows:

Only an expression can be specified in the selection list when the subconsultation is not entered with EXISTS.

That is, you are searching for more than one expression within a sub-volume. To solve this problem you must rewrite the first query to:

SET @D0 = (SELECT DATEADD(day, 0, GETDATE())
             FROM VW_Vendas);

Or:

SET @D0 = GETDATE();

SELECT @QUANTIDADE_CPS = COUNT(NUM_CP)
  FROM VW_Vendas;
  • I made the changes to my @QUANTIDADE_CPS variable, but now it says my NUM_CP column name is invalid. So I tried using SELECT before Count, and points out that my select syntax is wrong.

  • @Anaclara now that I have seen what you are trying to do. I suggest you share the responsibilities. I will change my answer

  • I made the changes the way you said, but for some reason, it didn’t work, because the error of only one expression can be specified reappeared.

  • @Anaclara maybe the error is in your view. Add its content to your question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.