2013-08-08 2 views
0

이 나는 ​​조건에 따라 저장 프로 시저 내 테이블에 값을 삽입하려고 :삽입 값은 SQL Server

alter procedure service_report_st2 
as 
insert into Service_report_step1(appointment_or_house) 
select 
case 
when Service_report_step1.card_uid in(select card_uid from visits where vidpos_kod = 'A') 
then '1' 

when Service_report_step1.card_uid in(select card_uid from visits where vidpos_kod = 'B') 
then '2' 

else '3' 
end 

오류가 Service_report_step1.card_uid에서 발견되지 않는 것입니다, 그러나 이것은이다 Service_report_step1의 첫 번째 열. appointment_or_housevisits 테이블에 이 포함되어 있으면 Service_report_step1에 '1', '2'또는 '3'을 포함해야하는 두 번째 열입니다.

도움을 주시면 감사하겠습니다.

짧은 예 :

Visits 표는 2 열이 있습니다 Card_uid 및 vidpos_kod

card_uid   vidpos_kod 
111-111    A 
222-222    B 
333-333    A 
444-444    C 

지금 Service_report_step1 테이블 card_uid있다 (모든 가능한 카드를 포함 열) 및 appointment_or_house 열

card_uid  appointment_or_house 
111-111    1 
222-222    2 
333-333    1 
444-444    1 

을 그래서 card_uidsService_report_step1에있는 경우와 같습니다. I는 554,133,210 Visitsvidpos_kod에 기초 appointment_or_house 열을 결정 I 예에서와 같이 정확하게 Service_report_step1 모든 데이터에 삽입해야

(A, C는 '1', B는 '2'이다).

+0

사용하는 것입니다 ..... –

답변

2

당신은 SELECT 문을 사용하고 있지만, FROM clause

없이 당신은 그런

INSERT INTO ... 
SELECT * 
FROM ... 

또는 무언가를 지정해야합니다.

다른 옵션은`SELECT` 당신이에서 행을 선택하고있는 테이블을 정의하는`FROM` 절을 부족 Table Value Constructor (Transact-SQL)

1
insert into Service_report_step1(appointment_or_house) 
select 
case vidpos_kod 
when 'A' then '1' 
when 'B' then '2' 
when 'C' then '3' 
end 
from visits 
where vidpos_kod like '[ABC]'