I am trying to insert some data into a SQL Server table from a C# application. Normally I would have no trouble doing this, but I am running into an error when I try to pass a variable in the insert subquery.
I have a table [CapitalRequest] where a [RequestNumber] is assigned an [ID]. I want to select that [ID] where [RequestNumber] = @capNum and INSERT it into [ExpenseItem].
Here is the error message:
'Subqueries are not allowed in this context. Only scalar expressions are allowed.'
Thanks in advance!
Here is my SQL code:
INSERT INTO [ExpenseItem]
(@iCat,@iDesc,@iCost,@iQnty,(SELECT [id] FROM [CapitalRequest] WHERE [capitalNumber] = @capNum))