我正在使用Microsoft Visual Studio 2017和SQL Server 2017。 当我在Visual Studio中运行此语句时,我没有收到任何错误:
@"
DECLARE @items table (item_id int, item_count int, item_type smallint)
INSERT INTO @items (item_id, item_count, item_type)
SELECT TOP 10 oi.item_id, COUNT(1) as item_count, 1 as item_type
FROM t_ord_item oi
INNER JOIN (
SELECT oi.basket_id
FROM t_ord_item oi
INNER JOIN t_ord_order o ON o.ord_id = oi.ord_id
WHERE oi.item_id = @item_id
AND oi.status_code <> 'del'
AND o.status_code <> 'del'
AND o.status_code <> 'can'
GROUP BY oi.basket_id
) as bsk ON bsk.basket_id = oi.basket_id
WHERE oi.item_id IS NOT NULL
AND oi.item_id <> @item_id
GROUP BY oi.item_id
ORDER BY item_count DESC
INSERT INTO @items (item_id, item_count, item_type)
SELECT TOP 10 oi.item_id, COUNT(1) as item_count, 2 as item_type
FROM t_ord_item oi
INNER JOIN (
SELECT login_name_created
FROM t_ord_item
WHERE item_id = @item_id
AND status_code <> 'del'
and login_name_created is not null
GROUP BY login_name_created
) as login ON login.login_name_created = oi.login_name_created
WHERE oi.item_id IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM @items temp WHERE temp.item_id = oi.item_id)
AND oi.item_id <> @item_id
GROUP BY oi.item_id
ORDER BY item_count DESC";
但是当我运行Web应用程序时,出现此错误:
System.Data.SqlClient.SqlException:
Incorrect syntax near the keyword 'INNER'.
Incorrect syntax near the keyword 'AS'.
Incorrect syntax near the keyword 'ORDER'.
Incorrect syntax near the keyword 'AS'.
Incorrect syntax near the keyword 'AS'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Incorrect syntax near the keyword 'CASE'.
Invalid usage of the option NEXT in the FETCH statement.
我以为我缺少空格,所以我试图添加,但是仍然是同样的问题。我已经像以前一样发布了代码,以便您可以帮助我检测问题强文本