I am newer to SQL and found an answer to my problem, but being new to this site it won't allow me to comment on it to get clarity about how it worked. I tried to embed a SQL query in excel and it wouldn't work until I SET NOCOUNT ON before my DECLARE. I was hoping someone could tell me WHY this fixed my issue, so I can understand it better. My original query ran fine in management studio, but excel did not like it. The link to the post where I found the answer is below. My query was similar to the example in the answer I found. Appreciate any insight!
Asked
Active
Viewed 901 times
0
-
I suggest you read here https://stackoverflow.com/questions/1483732/set-nocount-on-usage on SET NOCOUNT ON. But even after the read i couldn't see why omitting the SET NOCOUNT ON creates an error on excel – sup4eli Sep 02 '18 at 13:36
1 Answers
0
I'm not an expert in embedded sql in Excel but without SET NOCOUNT ON an additional resultset is returned with the number of rows affected. This would therefore return two resultsets.

Simon
- 764
- 4
- 8
-
Thanks Simon. What is confusing to me is that I have other embedded queries in excel that work just fine without SET NOCOUNT ON, but they don't have a DECLARE statement in them so I thought maybe there was some relationship there. – shan_sql_47 May 08 '17 at 21:43