By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,483 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,483 IT Pros & Developers. It's quick & easy.

Dynamic SQL query Multiple rows based on table names linked in another table

P: 1
Hello
I have a sql 2008 R2 problem that I’ve tried to accomplishing using dynamic sql but, no luck yet.
Expand|Select|Wrap|Line Numbers
  1. Create Table Events (
  2. PKID    int  Not Null,
  3. TimeStamp Datetime,
  4. EventID        int,
  5. Eventdata     int)
  6.  
  7. Create Table Eventdatalookup(
  8. Event    int,
  9. DataLookupTableName         varchar(100))
  10.  
  11. Create Table TypicalEventDesc1(
  12. EventData     int
  13. EventDataDesc        varchar(100)
  14. Create Table TypicalEventDesc2(
  15. EventData     int
  16. EventDataDesc        varchar(100)
  17.  
Im wanting to create a stored procedure that will lookup the description of the event id and event data in table Events based on a table name in another table. I have found examples of dynamic sql that will return the Desc for one row but there will be many many rows returned in this query.

Events.EventID--- EventDataLookup.Event
Events.EventData—TypicalEventDescX.EventData
The DataLookupTableName Contains the name of the table from which the Events.EventData can be tied to TypicalEventDesc1.EventDataDesc or tied to TypicalEventDesc2.EventDataDesc


Is what I’m wanting to do even possible?
Dec 7 '11 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,365
It's possible. The real question is why is the event data split across multiple tables when they should be in one table?
Dec 7 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.