Advertisement

02.21.2007 at 01:52PM PST, ID: 22404882
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

SQL Query - tables of dynamic tables

Asked by saw830 in MS System Center, MS SQL Server, SQL Server 2005

Tags: , , ,

Hi,
I need to query on some data.  The data is from SMS2003, stored in SQL2005, all on a Windows2003 server.  I write a few queries, but I consider myself an SQL beginner at best.  Normally, I write simple queries like "select column1, column2, column4 from a_table where column2 = 'something'".  That's about 90% of my writing ability.

Here's the challenge:
I need a query that can query a table and select a list of other tables and then list all or part of those tables.  It also needs to be able to know not to list one of those tables.  The schema for the first table is different from the rest, naturally, but the rest of the tables are all the same layout.

Here's an example:
MasterTable
FriendlyName     TrueName
===============================
Applications     Applications0
Applications     Applications1
Applications     Applications2
Systems          Systems0
Applications     Applications3
Applications     Applications4
Applications     Applications5
Systems          Systems1
===============================

Applicaitions(x)     <- (x) is a number, like 0, or 1, or 2, etc.
AppName     ProgName         Version
==========================================
Word        winword.exe      10.5.6.7
Notepad     notepad.exe      2.4.5.6
==========================================


I want to write something like:
Select AppName, ProgName
From UnionEverythingFoundIn
      (
      Select Truename
      From MasterTable
      Where
            FriendlyName = 'Applications'
            And
            TrueName <> 'Applications0'
      )

The problem is that I don't know of a command for "UnionEverythingFoundIn", and I don't know how to have SQL loop through the list to dynamically build the unions like "Applications1 Union Applications2 Union...etc".

We've done this in TQL like:
USE SMS_DB
GO
DECLARE get_TableNames CURSOR FOR
SELECT TrueName FROM MasterTable
Declare @Tablename as varchar(25)
OPEN get_TableNames
FETCH NEXT From get_TableNames into @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
      Exec('SELECT * From ' + @TableName)
      FETCH NEXT FROM get_TableNames into @TableName
END
CLOSE get_TableNames
DEALLOCATE get_TableNames
RETURN

This works in the SQL Analyser but it's not "normal SQL" enough for SMS to handle it as a query.

My options, in order of preference, are:
1. A query that SMS can handle that does it all.
2. A View or Proceedure that does the hard part, but can be seen or called by SMS one demand.
3. A Job or Proceedure that SQL can run on a schedule that creates yet another table that SMS can query simply (like "Select * from new_table")

I'm putting max points on this because we need it and haven't been able to figure it out ourselves.  Hopefully it will be a bit of a challenge, but not so much that you can't solve it.

Thanks,
AlanStart Free Trial
[+][-]02.21.2007 at 07:09PM PST, ID: 18584749

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2007 at 12:13PM PST, ID: 18620001

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2007 at 03:33PM PST, ID: 18621575

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2007 at 04:57PM PST, ID: 18621984

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2007 at 05:55PM PST, ID: 18622232

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.09.2007 at 04:57PM PDT, ID: 19250591

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.16.2007 at 07:59PM PDT, ID: 19300758

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS System Center, MS SQL Server, SQL Server 2005
Tags: sql, query, dynamic, table
Sign Up Now!
Solution Provided By: Computer101
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32