title: Error while connecting to SQL Server from pyspark
body: <pre class="lang-py prettyprint-override"><code>from pyspark.sql import SQLContext
  from pyspark import SparkContext
  
  from impala.dbapi import connect
  import sys
  
  sc = SparkContext("local", "first app")
  sqlContext = SQLContext(sc)
  
  with open(sys.argv[1]) as file:
      config = yaml.safe_load(file)
  print(config)
  
  table_name = 'loadout'
  
  df = sqlContext.read \
      .format("jdbc") \
      .option("url", config['db_config']['url']) \
      .option("dbtable", "(SELECT TOP 100 * FROM dbo.{0})".format(table_name)) \
      .option("user", config['db_config']['username']) \
      .option("password", config['db_config']['password']) \
      .option("driver", config['db_config']['driver']) \
      .load()
  
  df.show()
  
  </code></pre>
  
  <p>It is throwing error:</p>
  
  <pre><code>&gt; Traceback (most recent call last):   File
  &gt; "/home/rkumbar/ddl_generation/test.py", line 34, in &lt;module&gt;
  &gt;     .option("driver", config['db_config']['driver']) \   File "/opt/cloudera/parcels/CDH-5.12.1-1.cdh5.12.1.p0.3/lib/spark/python/lib/pyspark.zip/pyspark/sql/readwriter.py", line 139, in load   File
  &gt; "/opt/cloudera/parcels/CDH-5.12.1-1.cdh5.12.1.p0.3/lib/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py", line 813, in __call__   File
  &gt; "/opt/cloudera/parcels/CDH-5.12.1-1.cdh5.12.1.p0.3/lib/spark/python/lib/pyspark.zip/pyspark/sql/utils.py",
  &gt; line 45, in deco   File
  &gt; "/opt/cloudera/parcels/CDH-5.12.1-1.cdh5.12.1.p0.3/lib/spark/python/lib/py4j-0.9-src.zip/py4j/protocol.py",
  &gt; line 308, in get_return_value py4j.protocol.Py4JJavaError: An error
  &gt; occurred while calling o56.load. :
  &gt; com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near
  &gt; the keyword 'WHERE'.
  </code></pre>
  
  <p>My spark submit command:</p>
  
  <pre><code>spark-submit --driver-class-path /home/xyz/ddl_generation/mssql-jdbc-6.1.0.jre7.jar test.py config.yml
  </code></pre>