0

I have created a rather large SQL Query in Microsoft SQL Server Management Studio. I got the query running great in the studio. Now I want to bring that code into Excel to be able to access it and refresh as needed. But when I copy the code it cuts off about 1/3 of the way as if I've hit a character limit. Does anyone know a way around this?

M. Anderson
  • 9
  • 1
  • 4
  • Put it in a text box in Excel. Why exactly do you need this in Excel? – Kyle Oct 14 '16 at 15:18
  • I have written the code in SQL, but our system won't let me save the results into a new table. So I am trying to copy the code into a connection in Excel so that I can just Refresh the data when needed. Otherwise I have to open the SQL Studio, open the query, run the query, and then copy and paste the results into Excel. I have done this on numerous other queries but they didn't have near the logic this one does. So when I copy and paste the SQL Code, only about a 1/3 of it will copy. – M. Anderson Oct 17 '16 at 15:42
  • Use ADO and query the results directly into a worksheet. The SQL code will be housed in the VBE then. – Kyle Oct 17 '16 at 18:29
  • Kyle - I am not familiar with ADO at all. Any suggestions on how to get started? – M. Anderson Oct 19 '16 at 14:14
  • Add a reference to the `Microsoft ActiveX Data Objects x.x Library`. Then go read [this](http://stackoverflow.com/documentation/vba/3578/working-with-ado#t=201610191443053998065). That should give you a good idea. Post back with questions. – Kyle Oct 19 '16 at 14:44

1 Answers1

0

SSMS has limits..to overcome that,you can export to file like below

enter image description here

Community
  • 1
  • 1
TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
  • This seems to be more towards the result of the logic limits. Not copying the code from SQL Studio to a connection in Excel. Thanks though. – M. Anderson Oct 17 '16 at 15:43