我可以在INSERT值中使用SELECT语句吗?

时间:2009-06-24 11:53:28

标签: sql sql-server-2005 performance tsql

我试过了:

INSERT  INTO tbl_vaucher
        (
          vaucher_name,
          created_date
        )
VALUES  (
          ( SELECT TOP 1
                    con_full_name
            FROM    tbl_contact
          ),
          GETDATE()
        )

,获得:Subqueries are not allowed in this context. Only scalar expressions are allowed

我需要一个没有功能的解决方案。

1 个答案:

答案 0 :(得分:22)

INSERT
INTO    tbl_vaucher (vaucher_name, created_date)
SELECT  TOP 1
        con_full_name, GETDATE()
FROM    tbl_contact