SQL query not returning data

drushe

New Member
Joined
Mar 28, 2012
Messages
1
I need to return data from a database table whose name is in another table. Ex - TTT.best has only one record with the name of the best salesman and his current sales total. Database TTT has a table named for each salesman with the individual sales data. In an Excel query, I want to return data for the best salesman. I created a query like:
Code:
declare @name1 varchar(13) 
declare @cmdstr varchar(500) 
set @name1 = (select name from TTT.best )
set @cmdstr = 'SELECT [EMAIL="'+@name1+ '.customer"]'+ @name1 + '.customer[/EMAIL], 
Count(*) FROM TTT.'+ @name1 + '
group by ' + @name1 + '.customer'
execute(@cmdstr)
I can execute the query in the Microsoft SQL box and get results. But when I return the data to the spreadsheet, I get only ExternalData_1. No runs, drips or errors, but no data. Am I missing something?
Thanks, folks.

 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top