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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CSJeep
    New Member
    • Dec 2011
    • 1

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

    Hello
    I have a sql 2008 R2 problem that I’ve tried to accomplishing using dynamic sql but, no luck yet.
    Code:
    Create Table Events (
    PKID	int  Not Null,
    TimeStamp Datetime,
    EventID		int,
    Eventdata 	int)
    
    Create Table Eventdatalookup(
    Event	int,
    DataLookupTableName 		varchar(100))
    
    Create Table TypicalEventDesc1(
    EventData	 int
    EventDataDesc		varchar(100)
    Create Table TypicalEventDesc2(
    EventData	 int
    EventDataDesc		varchar(100)
    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.EventDat a—TypicalEventD escX.EventData
    The DataLookupTable Name Contains the name of the table from which the Events.EventDat a can be tied to TypicalEventDes c1.EventDataDes c or tied to TypicalEventDes c2.EventDataDes c


    Is what I’m wanting to do even possible?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's possible. The real question is why is the event data split across multiple tables when they should be in one table?

    Comment

    Working...