Я использую 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";
Но когда я запускаю веб-приложение, я получаю эту ошибку:
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.
Я думал, что мне не хватает пробелов, поэтому я пытался добавить, но проблема все та же. Я опубликовал код, как и раньше, чтобы вы могли помочь мне обнаружить проблемный текст