title: SQL Query within VS TableAdapter Query Configuration Wizard
body: <p>I am trying to write an SQL query within Visual Studio TableAdapter Query Wizard</p>
  
  <p>My SQL query is:</p>
  
  <pre><code>    DECLARE @SQL varchar(255);
  
  SET @SQL = ' SELECT * FROM dbAddress WHERE 1 = 1'
  
  IF @ApexLine1 = ''
      BEGIN
          SET @SQL = @SQL + ' AND addLine1 IS NULL '
      END
  ELSE
      BEGIN
          SET @SQL = @SQL + ' AND addLine1 = ''' + @ApexLine1 + ''''
      END
  
  IF @ApexLine2 = ''
      BEGIN
          SET @SQL = @SQL + ' AND addLine2 IS NULL '
      END
  ELSE
      BEGIN
          SET @SQL = @SQL + ' AND addLine2 = ''' + @ApexLine2 + ''''
      END
  
  IF @ApexLine3 = ''
      BEGIN
          SET @SQL = @SQL + ' AND addLine3 IS NULL '
      END
  ELSE
      BEGIN
          SET @SQL = @SQL + ' AND addLine3 = ''' + @ApexLine3 + ''''
      END
  
  IF @ApexZip = ''
      BEGIN
          SET @SQL = @SQL + ' AND addPostCode IS NULL '
      END
  ELSE
      BEGIN
          SET @SQL = @SQL + ' AND addPostCode = ''' + @ApexZip + ''''
      END
  
  IF @ApexCity = ''
      BEGIN
          SET @SQL = @SQL + ' AND addLine4 IS NULL '
      END
  ELSE
      BEGIN
          SET @SQL = @SQL + ' AND addLine4 = ''' + @ApexCity + ''''
      END
  
  IF @ApexProv = ''
      BEGIN
          SET @SQL = @SQL + ' AND addLine5 IS NULL '
      END
  ELSE
      BEGIN
          SET @SQL = @SQL + ' AND addLine5 = ''' + @ApexProv + ''''
      END
  
  EXEC(@SQL)
  </code></pre>
  
  <p>I get the error:</p>
  
  <p>'The Declare SQL contruct or statement is not supported'</p>
  
  <p>If I remove the Declare statement I get error:</p>
  
  <p>'The Set SQL construct or statement is not supported'</p>
  
  <p>Is there a work around for this?</p>
  
  <p>Thanks.</p>