Here is my query. i have two tables as example
In future i'll add more tables in a query.
Then how can i join those tables dynamically in single query
1) tblEmployee
- EmpId
- Name
- DOB
2) tblSalary
- EmpId
- TotalSalary
- PF
- NetSalary
How can i get the data. table names and field names are in variable with comma separated.
DECLARE @FieldNames VARCHAR(MAX) = 'Id, Name, NetSalary'
DECLARE @TableName VARCHAR(MAX) = 'tblEmployee, tblSalary'
SELECT @FieldNames FROM @TableNames
can i join this tables automatically with primary key and foreign key?
above query returns too many dummy data.