Mysql 基于输入参数获取资产详细信息的存储过程
我正在编写一个存储过程,根据传入的Mysql 基于输入参数获取资产详细信息的存储过程,mysql,Mysql,我正在编写一个存储过程,根据传入的类别ID获取详细信息,如果传递给它的类别ID不为null,我将基于类别ID获取详细信息,如果类别ID为null,我将获取其类别ID除3之外的所有详细信息,有人能帮我解决这个问题吗 我的程序如下: CREATE procedure [dbo].[SearchAssetdetails] ( @assetCategory as int = null, @assetType as int = null, @assetDescription as nvarchar(200
类别ID
获取详细信息,如果传递给它的类别ID
不为null,我将基于类别ID
获取详细信息,如果类别ID
为null,我将获取其类别ID
除3
之外的所有详细信息,有人能帮我解决这个问题吗
我的程序如下:
CREATE procedure [dbo].[SearchAssetdetails]
(
@assetCategory as int = null,
@assetType as int = null,
@assetDescription as nvarchar(200) = null,
@purchaseDate as datetime = null,
@validUpto as datetime = null)
as
begin
select ad.CategoryID,ad.AssetTypeId,ad.AssetDetailId,ad.AssetDescription,ad.Cost,ad.IsOwn,ad.LastModifiedby,ad.LastModifiedDatetime,ad.Location,ad.NoofLicences,ad.PurchaseDate,ad.SerialNumber,ad.ValidUpto,ad.VendorId,ad.Version,ad.WarrantyExpirationDate
from AssetDetails ad where
(ad.AssetDescription like (case when @assetDescription is not null then '%'+@assetDescription+'%' else ad.AssetDescription end)
and ad.CategoryID=(case when @assetCategory is not null then @assetCategory else ad.CategoryID end)
and ad.AssetTypeId=(case when @AssetType is not null then @AssetType else ad.AssetTypeId end)
and ad.PurchaseDate=(case when @purchaseDate is not null then @purchaseDate else ad.PurchaseDate end)
and ad.ValidUpto=(case when @validUpto is not null then @validUpto else ad.ValidUpto end)
) end;
由于where子句中的
和
条件,您对其他参数的输入可能与输入类别id
不匹配,因为为空
,但被替换为3
首先,选择具有其他参数的记录,并查看其中是否有任何记录获取类别id为3的记录。
我建议您向我们展示类别id为3的记录,以便更好地了解数据
否则我相信没有错误。您使用的是什么数据库管理系统mysql、oracle、sql server?是的,我找到了解决方案,在从数据库获取详细信息后,我使用类似LINQ的var res=从assetDetails where asset.categoryID中的asset中的分类id筛选结果=3选择资产。