Hi @Jreco ,
You need to use prepare query option and then query like below:
url = "jdbc:sqlserver://server_name:1433;database=db_name"
df = spark.read \
.format("jdbc") \
.option("url", url) \
.option("prepareQuery", "with cte as ( SELECT TOP 10 * FROM dbo.TestTb wt)") \
.option("query", "SELECT * FROM cte") \
.option("user", "user_name") \
.option("password", "password")
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver").load()
I've tested it and it works ๐