Note that there are some explanatory texts on larger screens.

plurals
  1. PODo I Need Cursors?
    text
    copied!<p>Just to say up front, I’m working with an existing schema (that isn’t exactly the best) and I have no control over it. I must work with it - I can't change it one bit.</p> <p>There is one company table with a record for each company, then each company gets its own set of tables that represent the business operations. To begin with, I’m interested in a specific table for each company. My task is to generate a single recordset output from all the companies’ “MyTables”</p> <p>Here’s a sample of what I have:</p> <pre><code>CREATE TABLE [dbo].[Company]( [timestamp] [timestamp] NOT NULL, [Name] [varchar](30) NOT NULL, [Short Code] [varchar](3) NOT NULL, CONSTRAINT [Company$0] PRIMARY KEY CLUSTERED([Name] ASC)) </code></pre> <p>If I SELECT all the Names from the Company table, I get (e.g.)<br> “Company A”, “Company B”, “Company C Inc.”</p> <p>And then I have one table for each company (all company specific tables have the exact same column definitions) with the following names (in company name: spaces remain, periods changed to underscores):</p> <pre><code>CREATE TABLE [dbo].[Company A$MyTable]( --Various columns ) </code></pre> <p>The “MyTable” name for “Company C Inc.” would be [Company C Inc_$MyTable]</p> <p>I was thinking of doing the T-SQL in a stored proc and then consuming that from the C# code that will present the data.</p> <p>With my limited SQL skills, I’m guessing I need to use cursors. Since I’ve not done much with cursors, I’m hoping someone here could give me a head start with this.</p> <p>Thanks,<br> --Ed</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload