本文介绍了我的sql更新过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此查询有疑问.请有人帮助我.

i have some doubt in this query .please someone help me.

CREATE PROCEDURE sp_insert_userdetailss
(
)
BEGIN
IF EXISTS(SELECT `name`,`email`,`phono no` FROM user_details 
WHERE email=email)
UPDATE user_details
SET `name`=`name`,email=email,`phone no`=`phone no`,photo=photo;
ELSE
INSERT INTO user_details(`name`,email,`phone no`,`photo`)
VALUES(`name`,`email`,`phone no`,`photo`);
SELECT MAX(user_details.id)
FROM user_details
INNER JOIN city ON user_details.city_id=city.id
INNER JOIN area ON user_details.area_id=area.id
INNER JOIN usertype ON user_details.type_id=usertype.id;
END;



我收到错误->



and i am getting the error->

[SQL] CREATE PROCEDURE sp_insert_userdetailss
(
)
BEGIN
IF EXISTS(SELECT `name`,`email`,`phono no` FROM user_details 
WHERE email=email)
UPDATE user_details
SET `name`=`name`,email=email,`phone no`=`phone no`,photo=photo;
ELSE
INSERT INTO user_details(`name`,email,`phone no`,`photo`)
VALUES(`name`,`email`,`phone no`,`photo`);
SELECT MAX(user_details.id)
FROM user_details
INNER JOIN city ON user_details.city_id=city.id
INNER JOIN area ON user_details.area_id=area.id
INNER JOIN usertype ON user_details.type_id=usertype.id;
END;

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE user_details
SET `name`=`name`,email=email,`phone no`=`phone no`,photo=p' at line 7

推荐答案

UPDATE user_details
SET [name]='name',email=email,[phone no]='phone no',photo=photo;



CREATE PROCEDURE sp_insert_userdetailss
           @name nvarchar(100), 
           @email nvarchar(100), 
           @phon_no nvarchar(100), 
           @photo nvarchar(100)
As
BEGIN
IF EXISTS(SELECT name,email,[phono no] FROM user_details WHERE email=@email)
	UPDATE user_details
	SET name=@name,email=@email,[phono no]=@phon_no,photo=@photo;
ELSE
	INSERT INTO user_details(name,email,[phono no],photo)
	values (@name,@email,@phon_no,@photo)

SELECT MAX(user_details.id)
FROM user_details
INNER JOIN city ON user_details.city_id=city.id
INNER JOIN area ON user_details.area_id=area.id
INNER JOIN usertype ON user_details.type_id=usertype.id;
END;


这篇关于我的sql更新过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 04:52