【问题标题】:Error showed by SQL server 2014SQL Server 2014 显示的错误
【发布时间】:2018-05-14 01:13:12
【问题描述】:
set @return=(SELECT u_id,u_pass from m_User where u_id = @userName AND u_pass=@userPass);

显示类似这样的错误

"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."

【问题讨论】:

  • @return 的数据类型?
  • 你只能SET一个值。 @return 不能有多个值。您正在尝试使用 SELECT u_id, u_pass 分配多个值。这就是您收到错误消息的原因。尝试分配一个值。如果您需要多个值,请改用 TABLE 类型。

标签: sql sql-server select subquery


【解决方案1】:

您不能在子查询中选择多个列。 在这里你选择了两列u_id,u_pass

根据需要只选择一个。

如果@return 是数据类型(例如,varchar、int)

set @return=(SELECT u_id from m_User where u_id = @userName AND u_pass=@userPass);

set @return=(SELECT u_pass from m_User where u_id = @userName AND u_pass=@userPass);

【讨论】:

    猜你喜欢
    • 2018-11-22
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    相关资源
    最近更新 更多