我需要验证尚未输入客户,在mysql中,我可以通过在下面的变量(@V_CustomerID)中选择客户ID来做到这一点。但是,ssms不喜欢该语法,还有另一种方法可以实现此目的吗?
Create procedure AddCustomer(
@CustomerFirstName as varchar(50),
@CustomerLastName as varchar(50),
@SiteName as varchar(50),
@CustomerPhone1 as varchar(20),
@CustomerPhone2 as varchar(20),
@CustomerAddress1 as varchar(20),
@CustomerAddress2 as varchar(20),
@CustomerCity as varchar(50),
@CustomerState as varchar(5),
@CustomerZip as char(5)
)
as
begin
declare @V_CustomerID as int,--use this to store the returned value
@V_CustomerExists as bit --use this to store the result of the if else condition
--First we should check if the customer data already exists in the table--
select dbo.customer.CustomerID
into @V_CustomerID
from
dbo.Customer
where
dbo.customer.FirstName = @CustomerFirstName and dbo.customer.LastName = @CustomerLastName and dbo.customer.sitename = @SiteName;
if @V_CustomerID is null
begin
--Yay! we can insert the customer--
insert into Customer
values(@CustomerFirstName,@CustomerLastName,@SiteName);
end
else
begin
set @V_CustomerExists = 1
print 'Customer already exists';
end
end
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。