Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 根据条件将值插入表中,sql server_Sql Server_Tsql_Stored Procedures_Sql Insert - Fatal编程技术网

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
子句,该子句定义您从哪个表中选择行。。。。。