插入值问题的存储过程 [英] store procedur for insert value problem

查看:57
本文介绍了插入值问题的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友
以下是我的存储过程代码

Hello friends
Below is my store procedure code

create procedure sp_branchinsert(@branchid int,@schoolname varchar(100),@branchname varchar(50),@createddateandtime datetime)
as
begin
declare @schooid int
select School_id from School where School_name=@schoolname;
set @schooid=School_id;
insert into Branch(Branch_id,School_id,Branch_name,Created_date_time)values(@branchid,@schooid,@branchname,@createddateandtime)
end



错误是设置行中的无效列school_id.我的任务是我想使用存储过程局部变量@schoolname从学校中选择school_id.然后需要将此Schoo_id值插入新表分支中.如果我的查询错误,如何为上述任务编写查询.



The error is invalid column school_id in the set line.what is my task is i want to select school_id from school using store procedure local variable @schoolname.and then this Schoo_id value is need to inserted into the new table branch. if my qurey is wrong, how to write query for the above task.

推荐答案

尝试类似以下操作:
Try something like this:
INSERT INTO Branch (schoolId, branchId) VALUES ((SELECT schoolId FROM School WHERE schoolName=@schoolname), @Branchid)


select School_id from School where School_name=@schoolname;
set @schooid=School_id;


更改此行,


change this lines with,

select @schooid=School_id from School where School_name=@schoolname;



祝您编码愉快!
:)



Happy Coding!
:)


尝试一下

您必须从选择查询中为@schoolId设置值.您不能单独设置.

错误:
try this

You have to set value for @schoolId from the select query. You cant set it separately.

Incorrect:
select School_id from School where School_name=@schoolname;
set @schooid=School_id;





正确的一个:
从学校中选择@ schooid = School_id,其中School_name = @ schoolname





Correct one:
select @schooid=School_id from School where School_name=@schoolname

create procedure sp_branchinsert(@branchid int,@schoolname varchar(100),@branchname varchar(50),@createddateandtime datetime)
as
begin
declare @schooid int
select @schooid=School_id from School where School_name=@schoolname
insert into Branch(Branch_id,School_id,Branch_name,Created_date_time)values(@branchid,@schooid,@branchname,@createddateandtime)
end


这篇关于插入值问题的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆