Can I use a SELECT statement inside an INSERT value?

I tried this:

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

received: Subqueries are not allowed in this context. Only scalar expressions are allowed.

I need a solution that will work without functions.

+3
source share
1 answer
INSERT
INTO    tbl_vaucher (vaucher_name, created_date)
SELECT  TOP 1
        con_full_name, GETDATE()
FROM    tbl_contact
+22
source

Source: https://habr.com/ru/post/1711168/


All Articles