Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert Function

Author  Topic 

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2008-12-16 : 12:31:46
I created a Table called "Application":

Application Name,  Application Description, 

 Blabalablabla,           blablalbaklbl     


I want to insert into the Application Table the Application Name from another Table Approver.

Approver Table
Approver Name, Application Name, Application_Name2, Application_Name3


How can I insert these three columns inside my new Application Table under Application Name column.

Thanks for the help!!!!!!!

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-12-16 : 12:45:54
Are you trying to insert distinct records or duplicate as well?

Insert Application ([Application Name])
select [Application Name]
from
(Select [Application Name] as [Application Name] from Approver
union
Select Application_Name2 from Approver
union
Select Application_Name3 from aprrover)t
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2008-12-16 : 12:54:05
There are Distinct Records. Thank You Sodeep
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 12:58:54
if sql 2005
Insert Application ([Application Name])
SELECT DISTINCT Application
FROM (SELECT * FROM Application) t
UNPIVOT(Application FOR ColValues IN ([Application Name], [Application_Name2], [Application_Name3]))p
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2008-12-16 : 14:22:44
I am sorry, I am a little confuse.
The Application_Name, Application_Name2, Application_Name3 belongs to: "Approver Table"
I want to insert this three columns
Insert Into: "Aplication Table"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 14:24:57
quote:
Originally posted by osirisa

I am sorry, I am a little confuse.
The Application_Name, Application_Name2, Application_Name3 belongs to: "Approver Table"
I want to insert this three columns
Insert Into: "Aplication Table"



oops then it should be

Insert Application ([Application Name])
SELECT DISTINCT ApplicationVal
FROM (SELECT * FROM Approver) t
UNPIVOT(ApplicationVal FOR ColValues IN ([Application Name], [Application_Name2], [Application_Name3]))p
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2008-12-16 : 14:26:34
Thank You Visakh16
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 00:14:04
welcome
Go to Top of Page
   

- Advertisement -