SQL Server Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, , = , , =
Try this:
SELECT
od.Sku,
od.mf_item_number,
od.Qty,
od.Price,
s.SupplierId,
s.SupplierName,
s.DropShipFees,
si.Price as cost
FROM
OrderDetails od
INNER JOIN Supplier s on s.SupplierId = od.Mfr_ID
INNER JOIN Group_Master gm on gm.Sku = od.Sku
INNER JOIN Supplier_Item si on si.SKU = od.Sku and si.SupplierId = s.SupplierID
WHERE
od.invoiceid = '339740'
This will return multiple rows that are identical except for the cost
column. Look at the different cost values that are returned and figure out what is causing the different values. Then ask somebody which cost value they want, and add the criteria to the query that will select that cost.
Subquery returned more than 1 value.This is not permitted when the subquery follows =,!=,,=,,= or when the subquery is used as an expression
The problem is that these two queries are each returning more than one row:
select isbn from dbo.lending where (act between @fdate and @tdate) and (stat ='close')
select isbn from dbo.lending where lended_date between @fdate and @tdate
You have two choices, depending on your desired outcome. You can either replace the above queries with something that's guaranteed to return a single row (for example, by using SELECT TOP 1
), OR you can switch your =
to IN
and return multiple rows, like this:
select * from dbo.books where isbn IN (select isbn from dbo.lending where (act between @fdate and @tdate) and (stat ='close'))
Subquery returned more than 1 value. This is not permitted when the subquery
The subquery select name from @collname
returns more than one value, this is why you can't use =
.
Use IN
predicate instead of =
:
where li.title=@title and coll.name in (select name from @collname)
SQL Server - Subquery returned more than 1 value. This is not permitted error
In SQL CASE
is an expression that returns a single scalar value. It cannot be used like in procedural languages to control execution flow.
You can try rewritting your WHERE
clause as follows:
WHERE
(@MCO = '99' AND MCO_ID IN (SELECT MCO_ID FROM @ALL_MCO))
OR
(@MCO != '99' AND MCO_ID = @MCO)
Subquery returned more than 1 value How To Fix
You probably don't need to re-set the code and the name, so just set one column:
UPDATE [dbo].[FreshStock]
SET [Stock] = (SELECT SUM([Box])
FROM [dbo].[PurchaseInvoiceDetails]
WHERE [ProductName] = 'Makki Rusk'
)
WHERE ProductName = 'Makki Rusk';
SQL Subquery returned more than 1 value. This is not permitted when the subquery
I would recommend that you use exists
:
SELECT ot.*
FROM Schedule_OverdueTasks ot
WHERE EXISTS (SELECT 1
FROM V_CONSTAT_PROJ_DATES pd
WHERE ot.Job_No LIKE pd.area_id + '%' AND
AREA_DESC IN ('aaa', 'bbb')
);
Related Topics
SQL Server: How to Insert into Two Tables At the Same Time
How to List the Tables in a Sqlite Database File That Was Opened With Attach
Count the Occurrences of Distinct Values
SQL Server Process Queue Race Condition
How to Create a Comma-Separated List Using a SQL Query
How to Use Count and Group by At the Same Select Statement
SQL Server, Division Returns Zero
In Sql, How to "Group By" in Ranges
Delete Duplicate Rows from Small Table
How to Combine Date from One Field With Time from Another Field - Ms SQL Server
How to Tell When a MySQL Table Was Last Updated
Add a Column With a Default Value to an Existing Table in SQL Server