This repository was archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
CREATE PROCEDURE Error #7
Copy link
Copy link
Open
Description
I have a procedure.
When I create it, will throw a error:
CREATE PROCEDURE AddTrade
@buyerId nvarchar(50),
@platform INT,
@mobile varchar(20),
@telephone varchar(20),
@orderId varchar(50),
@fullname nvarchar(20)
AS
BEGIN
if not exists(select 1 from [Account] where id=@buyerId)
begin
INSERT INTO [Account](id) VALUES(@buyerId)
end
if not exists(select 1 from [Mobile] where id=@mobile)
begin
INSERT INTO [Mobile](id) VALUES(@mobile)
end
if @telephone <> @mobile and not exists(select 1 from [Mobile] where id=@telephone)
begin
INSERT INTO [Mobile](id) VALUES(@telephone)
end
if not exists(select 1 from [Trade] where orderId=@orderId)
begin
INSERT INTO [Trade](orderId,[platform],fullname) VALUES(@orderId,@platform,@fullname)
end
INSERT EDGE INTO Account.HasTrade
SELECT a,t FROM Account a , Trade t
WHERE a.id = @buyerId AND t.orderId = @orderId ;
INSERT EDGE INTO Account.UseMobile
SELECT a,t FROM Account a , Mobile t
WHERE a.id = @buyerId AND t.id = @mobile ;
INSERT EDGE INTO Mobile.HasTrade
SELECT a,t FROM Mobile a , Trade t
WHERE a.id = @mobile AND t.orderId = @orderId ;
INSERT EDGE INTO Mobile.HasAccount
SELECT a,t FROM Mobile a , Account t
WHERE a.id = @mobile AND t.id = @buyerId ;
INSERT EDGE INTO Trade.UseAccount
SELECT t,a FROM Account a , Trade t
WHERE a.id = @buyerId AND t.orderId = @orderId ;
INSERT EDGE INTO Trade.UseSecMobile
SELECT t,a FROM Mobile a , Trade t
WHERE a.id = @telephone AND t.orderId = @orderId ;
INSERT EDGE INTO Trade.UseMainMobile
SELECT t,a FROM Mobile a , Trade t
WHERE a.id = @mobile AND t.orderId = @orderId ;
if not (@telephone=@mobile) -- the same as @telephone<>@mobile
begin
INSERT EDGE INTO Account.UseMobile
SELECT a,t FROM Account a , Mobile t
WHERE a.id = @buyerId AND t.id = @telephone ;
INSERT EDGE INTO Mobile.HasTrade
SELECT a,t FROM Mobile a , Trade t
WHERE a.id = @telephone AND t.orderId = @orderId ;
INSERT EDGE INTO Mobile.HasAccount
SELECT a,t FROM Mobile a , Account t
WHERE a.id = @telephone AND t.id = @buyerId ;
end
END"And the if block diff position in code ,the error is different.
I resolve this by the code:
if (@telephone=@mobile)
begin
return
end
INSERT EDGE INTO Account.UseMobile
SELECT a,t FROM Account a , Mobile t
WHERE a.id = @buyerId AND t.id = @telephone ;
INSERT EDGE INTO Mobile.HasTrade
SELECT a,t FROM Mobile a , Trade t
WHERE a.id = @telephone AND t.orderId = @orderId ;
INSERT EDGE INTO Mobile.HasAccount
SELECT a,t FROM Mobile a , Account t
WHERE a.id = @telephone AND t.id = @buyerId ;Metadata
Metadata
Assignees
Labels
No labels