简体   繁体   中英

Column name or number value not match error from stored procedure

Here is my stored procedure code. When I run this code with all needed parameters, I get an error

Column name or number of supplied values does not match table definition

Anyone can give me a hint about what's wrong with this SQL?

Note: I am using Microsoft SQL Server.

USE [TestDataBase]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[GetProductsByKeyword] 
    @Keyword NVARCHAR(255) = NULL,
    @MinPrice FLOAT = NULL,
    @MaxPrice FLOAT = NULL,
    @MaxNumberOfSales FLOAT = NULL,
    @MinNumberOfSales FLOAT = NULL
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @ItemsTable TABLE (title NVARCHAR(255))

    DECLARE @Query NVARCHAR(MAX)

    SET @Query='select top 500 * from Products where ID in (SELECT TOP 10000 CAST(KEY_TBL.[KEY] AS BIGINT) FROM CONTAINSTABLE (Products, Title, '+char(39)+@Keyword++char(39)+') AS KEY_TBL ORDER BY RANK DESC)'

    PRINT @Query

    INSERT INTO @ItemsTable 
        EXEC sp_Executesql @Query


    SELECT * FROM @ItemsTable           

    SET NOCOUNT OFF;
END;

It would appear that your "select top 500 *…" query is returning more columns than your table variable can handle. Either change the * to be one column or change the table variable definition to cover the output of the query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM