SQL 根据第二个表中的搜索条件从第一个表中检索数据



i 有 2 个表 我想根据第二个表上应用的条件从第一个表中获取数据。

PHARMASTOCK(1)      Pharma Products(2)
ID                  ProductID   
ProductID           GenericName 
TradeName           TradeName   
MRP                 Supplier    
Rate                Manufacturer    
Stock               PurchasePTR 
Batch               UnitRate    
Expiry              MRP 
StockSection    

这是我编写的SQL存储过程,但它不起作用不出所料!

@StockSupplier varchar(50), @StockManufacturer Varchar(50)
AS

SELECT  PharmaStock.ProductID,PharmaStock.TradeName,PharmaStock.MRP,Rate,Batch,Expiry,StockSection,Stock,Supplier,Manufacturer 
from PharmaStock 
    Full JOIN PharmaProducts ON PharmaStock.ProductID = PharmaProducts.ProductID 
where Supplier  like + @StockSupplier + '%' and Manufacturer  like + @StockManufacturer + '%'
order by Manufacturer asc
    SELECT  PharmaStock.ProductID, 
PharmaStock.TradeName, 
PharmaStock.MRP, 
PharmaStock.Rate, 
PharmaStock.Batch, 
PharmaStock.Expiry, 
PharmaStock.StockSection, 
PharmaProducts.Supplier, 
PharmaProducts.Manufacturer  
FROM PharmaStock 
        INNER JOIN  PharmaProducts ON PharmaStock.ProductID = PharmaProducts.ProductID WHERE PharmaProducts.Supplier  LIKE  '%%' and PharmaProducts.Manufacturer  LIKE  '%%' 
ORDER BY PharmaProducts.Manufacturer asc

为供应商和制造商传递字符串以进一步过滤联接结果。

SELECT  PharmaStock.ProductID,PharmaStock.TradeName,PharmaStock.MRP,Rate,Batch,Expiry,StockSection,Stock,Supplier,Manufacturer 
from PharmaStock 
INNER JOIN PharmaProducts ON PharmaStock.ProductID = PharmaProducts.ProductID 
where Supplier  like  @StockSupplier + '%' and Manufacturer  like  @StockManufacturer + '%'
order by Manufacturer asc
SELECT  PS.ProductID,PS.TradeName,PS.MRP,PS.Rate,PS.Batch,PS.Expiry,PS.StockSection,PS.Stock,PP.Supplier,PP.Manufacturer 
    from PharmaStock PS
        inner JOIN PharmaProducts PP ON PS.ProductID = PP.ProductID 
    where Supplier  like CONCAT(@StockSupplier , '%') and Manufacturer  like CONCAT(@StockManufacturer ,'%') order by Manufacturer asc

在查询中更改了连接函数,然后更改了加号(需要删除 like 之后(。

相关内容

  • 没有找到相关文章

最新更新