WHERE CONTAINS 没有 return 数据
WHERE CONTAINS does not return data
包含和喜欢不适用于我的变量。
我尝试使用关键字 LIKE
和 CONTAINS
@ItemSupplied nvarchar (50)
as
begin
set nocount on;
SELECT [Name]
FROM Suppliers
where CONTAINS(ItemSupplied, @ItemSupplied)
order by [Name];
end
我也试过了
@ItemSupplied nvarchar (50)
as
begin
set nocount on;
SELECT [Name]
FROM Suppliers
where ItemSupplied LIKE @ItemSupplied
order by [Name];
end
我也想知道供应特定物品的供应商的名称,即使他们也供应其他物品。
如果你想使用 like 和一个变量,你可以使用 concat 来构建一个有效的 like 模式
SELECT [Name]
FROM Suppliers
where ItemSupplied LIKE concat('%', @ItemSupplie, '%')
order by [Name];
刚刚在 MSSQL 中对此进行了测试
DECLARE @ItemSupplied nvarchar (50)
SELECT [Name]
FROM Suppliers
WHERE ItemSupplied LIKE '%' + LTRIM(RTRIM(@ItemSupplied)) + '%'
ORDER BY [Name];
包含和喜欢不适用于我的变量。
我尝试使用关键字 LIKE
和 CONTAINS
@ItemSupplied nvarchar (50)
as
begin
set nocount on;
SELECT [Name]
FROM Suppliers
where CONTAINS(ItemSupplied, @ItemSupplied)
order by [Name];
end
我也试过了
@ItemSupplied nvarchar (50)
as
begin
set nocount on;
SELECT [Name]
FROM Suppliers
where ItemSupplied LIKE @ItemSupplied
order by [Name];
end
我也想知道供应特定物品的供应商的名称,即使他们也供应其他物品。
如果你想使用 like 和一个变量,你可以使用 concat 来构建一个有效的 like 模式
SELECT [Name]
FROM Suppliers
where ItemSupplied LIKE concat('%', @ItemSupplie, '%')
order by [Name];
刚刚在 MSSQL 中对此进行了测试
DECLARE @ItemSupplied nvarchar (50)
SELECT [Name]
FROM Suppliers
WHERE ItemSupplied LIKE '%' + LTRIM(RTRIM(@ItemSupplied)) + '%'
ORDER BY [Name];