0
sp_executesql的我寫的查詢:如何使用帶參數
DECLARE @Col_Select NVARCHAR(10);
SET @Col_Select = N'[od.orderID]';
DECLARE @Query NVARCHAR(4000);
SET @Query = N'SELECT quantity, COUNT(o.orderID) FROM orders o LEFT OUTER JOIN [order details] od ON o.orderid = @Col_Select group by od.quantity';
EXEC sp_executesql @Query,@Col_Select
什麼是錯我的查詢?
我得到這個錯誤:
Incorrect syntax near 'od.orderI)SELECT quantity,COUNT(o.orderID) FROM orders o LEFT OUTER JOIN [order details'.
你還可以分享[sp_executesql]的代碼嗎? – Dorin
@Dorin請參閱:http://msdn.microsoft.com/en-us/library/ms188001.aspx –