Click here to Skip to main content
15,881,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have three table
1) SysSettings 2) SysSettingsDep 3) SysSettingsMachine
now, we want to merge this table according the following condition-:
1) merge them to one table that's name "SysSettingsCustomer" by column "SettingKey"
2) when merge them i have a column "TableName" to show "settingKey" Which table is yours
I want the result like this:
SysSettingKey _ TableName
------------------------------
CompanyName _ SysSettingDep

I hope you understand my problem so, please help me.
tnx
_Amir
Posted
Updated 9-Oct-12 23:36pm
v4
Comments
skydger 10-Oct-12 4:51am    
Have you tried to create such a query? Where have you stuck?
amirmohamad 10-Oct-12 5:32am    
Yes i want to create query,
Om Prakash Pant 10-Oct-12 5:38am    
Agree that you want to create a query, but what all you have tried so far?
amirmohamad 10-Oct-12 5:51am    
I use this code but dosen't work:
select B.SettingKey SettingKey from dbo.SysSettings A
inner join dbo.SysSettingsDep B on A.SettingKey = B.SettingKey
union
select C.SettingKey SettingKey from dbo.SysSettings A
inner join dbo.SysSettingsMachine C on A.SettingKey = C.SettingKey

1 solution

If I understand your question in a right way, I think the following solution could be useful.
SQL
select B.SettingKey SettingKey, 'SysSettingsDep' AS TableName
  from dbo.SysSettings A 
 inner join dbo.SysSettingsDep B on A.SettingKey = B.SettingKey
 union 
select C.SettingKey SettingKey, 'SysSettingsMachine' AS TableName
  from dbo.SysSettings A
 inner join dbo.SysSettingsMachine C on A.SettingKey = C.SettingKey
 
Share this answer
 
Comments
amirmohamad 11-Oct-12 1:49am    
is not my answer but helpful tank's

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900