Sql server 根据条件将值插入表中,sql server
我尝试根据以下条件在存储过程的表中插入值:Sql server 根据条件将值插入表中,sql server,sql-server,tsql,stored-procedures,sql-insert,Sql Server,Tsql,Stored Procedures,Sql Insert,我尝试根据以下条件在存储过程的表中插入值: 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_st
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\u report\u step1中。未找到卡片uid
,但这是Service\u report\u step1
表中的第一列<代码>预约或住店是第二列,如果访问
表包含卡uid
在服务报告第1步中
,则应包含“1”、“2”或“3”
我将感谢任何帮助
简短示例:
visions
表有两列:Card\u uid和vidpos\u kod
card_uid vidpos_kod
111-111 A
222-222 B
333-333 A
444-444 C
现在Service\u report\u step1
表中有card\u uid(包含所有可能卡片的列)和appointment\u或house列
card_uid appointment_or_house
111-111 1
222-222 2
333-333 1
444-444 1
因此,如果我在服务报告
步骤1中有与访问
中相同的卡片
,我会根据访问
中的vidpos_kod
列来确定预约或
(A,C
是'1',B
是'2'))
我需要在
服务报告\u步骤1中正确插入所有数据,如示例所示。您使用的是select语句,但没有FROM子句
您需要指定
INSERT INTO ...
SELECT *
FROM ...
或者类似的
另一个选项是使用select语句,但不使用FROM子句
您需要指定
INSERT INTO ...
SELECT *
FROM ...
或者类似的
另一个选项是使用您的SELECT
缺少一个FROM
子句,该子句定义您从哪个表中选择行…..SELECT
缺少一个FROM
子句,该子句定义您从哪个表中选择行。。。。。