Microsoft Visual Studio 2019 Execute SQL Task Editor Syntax Errors Encountered

83 views Asked by At

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.

1

There are 1 answers

0
Jeff On
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 = ?;