SQL高级查询

时间:2013-04-23 06:08:36

标签: php mysql sql

我正在尝试更新如果存在或插入(如果不存在)但此查询由于某种原因不起作用

DECLARE @serverID varchar(60)
SET @serverID='(SELECT `c_server` FROM `admin_settings` WHERE `member_id`='%1')'
IF EXISTS (SELECT `id` FROM `s_advanced_info` WHERE `s_id` = @serverID)
UPDATE
    `s_advanced_info`
SET
    `s_hostname`='%2',
    `s_password`='%3',
    `s_admin_password`='%4',
    `s_motd`='%5',
    `s_sigcheck`='%6',
    `s_maxplayers`='%7',
    `s_kickduplicate`='%8',
    `s_sidechat`='%9',
    `s_von`='%10',
    `s_vonquality`='%11',
    `s_datetime_type`='%12',
    `s_static_date`='%13',
    `s_static_time`='%14'
WHERE
    `s_id` = @serverID
ELSE
INSERT INTO
    `s_advanced_info`
VALUES
    ('',@serverID,'%2','%3','%4','%5','%6','%7','%8','%9','%10',
    '%11','%12','%13','%14')

当我在mysql控制台中尝试它时,它说错误在这里:

DECLARE @serverID varchar(60) SET @serverID ='(SELECT c_server FROM admin_settings WHERE member_id ='%1')'

错误是什么意思以及如何纠正错误?

1 个答案:

答案 0 :(得分:0)

试试这个:DECLARE @serverID varchar(60)SET @serverID =(SELECT c_server FROM admin_settings WHERE member_id ='%1')

似乎您将serverId变量设置为恰好是sql-query的字符串。这真的是你想要做的吗?