-1

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

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_serverFROM admin_settingsWHERE member_id= '%1')'

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

4

1 回答 1

0

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

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

于 2013-04-23T06:43:41.120 回答