0

Trying to build a query on Execute SQL Task Editor.

SELECT ? =  CONVERT(VARCHAR(10), COUNT(DISTINCT Email))
FROM            [xxx].[dbo].[DataTEST] AS D_Test INNER JOIN
                         [xxx].[dbo].[ListsTEST] AS L_Test ON D_Test.ListId = L_Test.Id
WHERE        L_Test.[DataSent] = 0 AND Email IS NOT NULL

When building the Query I get the error:

Error in SELECT clause: 'expression near '='.

Missing FROM clause.

Unable to parse query text.

Do I need to use '?=' for this query? Im only using that as I am emulating the .dtsx file that I am trying to diagnose/ reverse engineer.

Ive ran the query without the ?= on SQL Management Studio and it gives me the data that I want but Im unsure if me running it without that wont generate the same results.

jarlh
  • 42,561
  • 8
  • 45
  • 63
Lulu
  • 1
  • The ? is a placeholder for a parameter - have you defined the parameter for the Execute SQL Task? Another way to approach this is to declare a variable - return the results of the query to that variable and then assign the ? to that variable. – Jeff Dec 29 '22 at 22:14

1 Answers1

0
Declare @output varchar(10) = '';

 Select @output = count(Distinct Email))
   From [xxx].[dbo].[DataTEST] AS D_Test
  Inner Join [xxx].[dbo].[ListsTEST] AS L_Test ON D_Test.ListId = L_Test.Id
  Where L_Test.[DataSent] = 0 
    And Email Is Not Null;

    Set @output = ?;
Jeff
  • 512
  • 2
  • 8