SQL Server将表列插入存储过程

时间:2017-11-21 06:11:54

标签: sql-server stored-procedures

是否可以从存储过程中插入未在任何连接中声明的表列?例如,

SELECT
    a.employee, b.department, a.time <= dbo.table_name.column 
FROM
    NGAC_AUTHLOG AS a 
INNER JOIN
    NGAC_USERINFO AS b ON a.ID = b.UserID

我得到的只是这个错误,“多部分标识符”......“无法绑定。”有没有办法在不使用连接的情况下调用数据库表列?

提前致谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT
    a.employee, b.department, (case when a.time <= (select top 1 column from dbo.table_name) then 'True' else 'False' end) TrueOrNot
FROM
    NGAC_AUTHLOG AS a 
INNER JOIN
    NGAC_USERINFO AS b ON a.ID = b.UserID