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

  • Can this stored procedure be modified to work properly?  When trying to save, SQL Server returns the error message:  Only one expression can be specified in the select list when the subquery is not introduced with EXISTS

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    ALTER PROCEDURE [dbo].[spAddCompanySubcontractors]
        -- Add the parameters for the stored procedure here
        @CompanyID INT,
        @SubcontractorID INT,
        @strTradeID NVARCHAR(255)
    AS
    BEGIN
        SET NOCOUNT ON;
        INSERT INTO dbo.tblCompanySubcontractors
        (
            CompanyID,
            SubcontractorID,
            TradeID
        )
        VALUES
        (
            (SELECT t1.CompanyID, t1.SubcontractorID,t2.value AS TradeID FROM
            (SELECT @CompanyID AS CompanyID, @SubcontractorID AS SubcontractorID) t1 CROSS JOIN
            (SELECT value FROM STRING_SPLIT(@strTradeID ,',')) t2)
        )
    END

  • Eliminate the VALUES clause, and leave it's query behind.   As you are using SELECT, you don't want to use a VALUES clause, as within that context, SQL Server wll expect single values as opposed to a SELECT statement. and if you are using a SELECT, you don't need VALUES.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Thanks!  That worked!

  • cchapel - Tuesday, July 31, 2018 10:38 AM

    Thanks!  That worked!

    You're very welcome.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply