2014-06-17 2 views
0

아래 테이블 3 개가 있습니다.여러 테이블 데이터를 시간 테이블에 임시 테이블에 삽입하십시오.

표 A : (갖는 하나의 열 직원 ID)

Employee Id 
    101 
    102 
    103 

표 B :

EmpName 
Sai 
sarath 
vijay 

표 C (한칸 EmployeeName을 가짐) (데 한칸 부서명)

DeptName**. 
IT 
ACCOUNTS 
MANAGEMENT 

여기 하나의 임시 테이블에 세 개의 테이블 열 값을 모두 삽입하려고합니다.

Create table #mytable (employeeid nvarchar(255),empname nvarchar(255),deptname nvarchar(255)) 

insert into #mytable (employeeid) 

select employeeid from tableA 
insert into #mytable (empname) 

select empname from tableB 
insert into #mytable (deptname) 

select deptname from tableC 

좋아하지만 여기 내 임시 테이블 (즉) #mytable 나를 아래 표와 같은 결과를 제공합니다.

**Employeeid    Empname    DeptName** 
    101       null     null 
    102       null     null 
    103       null     null 
    null      sai     null 
    null      Sarath     null 
    null      vijay     null 
    null      null     IT 
    null      null     ACCOUNTS 
    null      null     MANAGEMENT 

하지만 난 임시 테이블 즉, 번호로 한 번에 NOT NULL values.Please가 삽입에 대한 어떤 제안을 나에게 세 개의 테이블 즉 A, B, C를 줄 경우에만 데이터 행을 표시 mytable.And 포함하는 데이터 만 표시하고 싶어 행. 내가 오류

아래 얻고있다

insert into tb_MBUPSheetData123 ([BusinessStrategyMessaging],Capability,[DealSource],Language,LicenseType,[Proactive activity],[Proposal Type],RFXSolution, 
    SLBusinessSolutionArea,SolutionForProposal,SupportingSolution,Conversations,TopicForProposal,SalesDeskAgentAlias) 

values ((select [BusinessStrategyMessaging] from tb_MBUPSheetData where BusinessStrategyMessaging is not null), 
(select [DealSource] FROM tb_MBUPSheetData where DealSource is not null), 
(select [Capability] FROM tb_MBUPSheetData where Capability is not null), 
(select [Language] FROM tb_MBUPSheetData where Language is not null) 
,(select [LicenseType] FROM tb_MBUPSheetData where LicenseType is not null), 

(select [Proactive activity] FROM tb_MBUPSheetData where [Proactive activity] is not null), 
(select [ProposalType] FROM tb_MBUPSheetData where [Proposal Type] is not null), 
(select[RFXSolution] FROM tb_MBUPSheetData where RFXSolution is not null), 
(select [SLBusinessSolutionArea] FROM tb_MBUPSheetData where SLBusinessSolutionArea is not null), 
(select [SolutionForProposal]FROM tb_MBUPSheetData where SolutionForProposal is not null), 
(select [SupportingSolution] FROM tb_MBUPSheetData where SupportingSolution is not null), 
(select Conversations FROM tb_MBUPSheetData where Conversations is not null), 
(select [TopicForProposal] FROM tb_MBUPSheetData where TopicForProposal is not null), 
(select [SalesDeskAgentAlias] FROM tb_MBUPSheetData where SalesDeskAgentAlias is not null)) 

이하 그러나 같은

그리고 내가 시도 쿼리는 하위 쿼리는 1 개 이상의 값을 반환했습니다. 서브 쿼리는 다음 경우는 허용되지 않습니다 =,! =, <, < =,>,> = 또는 하위 쿼리는 식으로 사용하는 경우. 명세서가 종료되었습니다.

어떤 제안 ...

답변

0

먼저 당신이 모든 항목을 원한다면 당신이 시도 할 수

insert into mytable(employeeid,empname,deptname) select a.Eamployee_Id,b.EmpName,c.DeptName from table_a a,table_b b,table_c c where a.Eamployee_Id=b.Eamployee_Id and a.Eamployee_Id=c.Eamployee_Id; 
0

처럼 구문 쓸 수있는 직원 ID 가지고와 같은 외래 키 관계를 가지고해야합니다 세 개의 테이블 ! #temp 테이블에 시간 : -. 서브 쿼리는 =, =, <, <= , >,> = 또는 때 subque 다음에 올 때 부질 "와 같은 오류가 1 개 이상의 값을 반환

insert into #mytable values(select employeeid from tableA where_condition,select empname from tableB where_condition,select deptname from tableC where_condition); 
+0

내가 무엇입니까이 허용되지 않습니다 ry는 표현식으로 사용됩니다. 명세서가 종료되었습니다. – user3643469

+0

@ user3643469 ans에서 쓴대로 올바른 "where condition"을 제공 했습니까? – Krishna

+0

다음과 같이 조건을 부여 할 수 있습니다. (empid에서 id 선택 = 101) (empname에서 EmpName을 선택하십시오. EmpName = 'Sai'), (DeptName에서 DeptName을 DeptName = 'IT'로 선택하십시오. – Krishna

관련 문제