vendredi 5 juin 2015

Get Table name from another query result

I have a table as like below:

Table AuditLog(
Reference varchar(10) [primary key],
TableName varchar(10),
ModifiedColumn varchar(10),
ChangeData varchar(max),
TableReference varchar(10)
)

I am trying to achieve following query:

select *,
    (select accountNumber from [AuditLog.TableName] where Reference = AuditLog.TableReference ) 
    from AuditLog

AuditLog table column 'TableName' contain table name of that database. I need to load accountnumber from that table base on TableReference.

What's the right way to have table name populated dynamically?

Aucun commentaire:

Enregistrer un commentaire