如何将null传递到日期时间字段,我在fromdate和todate之间以及根据部门,类别等处理数据... [英] How to pass null to a date time filed where i am taking data between fromdate and todate and also based on department,category etc...
问题描述
如何将null传递到日期时间字段,其中我在fromdate和todate之间以及部门,类别等之间获取数据....
我的查询如下:
SELECT a.AssetId,a.SerialNo,a.ServiceTag,a.CostCenterId,a.AssetStatusId,a.AssetConditionId,a.Description,a.AssetEntryDate,a.RefId,a.RefModule,a.LoginId,
a.StoreStockId,a.AssetNo,a.BarCode,a.AssetPict,a.Notes,i.ItemName,m.Model,it.ItemType,c.CategoryName,b.BrandName,ac.AssetCondition ,cc.CostCenter,
CASE,当taissue.RefId = 0那么''没有分配''当taissue.RefModule =''D''那么
(SELECT Department
来自TblDepartment
WHERE DepartmentId = taissue.RefId)ELSE
(SELECT PersonName
来自TblPerson
WHERE PersonId = taissue.RefId)END AS [user],ast.AssetStatus,s.PurchaseRate,s.POInfo,s.WarrantyDate,v.VendorName,sm.PurDate,sm.PONo
来自TblAsset作为内部联系
TblStoreStock AS ss on a.StoreStockId = ss.StoreStockId INNER JOIN
TblStock AS s ON s.StockId = ss.StockId INNER JOIN
TblStoreEntryMaster AS sm ON sm.PurchaseId = s.PurchaseId INNER JOIN
TblItem AS i ON s.ItemId = i.ItemId INNER JOIN
TblModel AS m ON m.ModelId = i.ModelId INNER JOIN
TblIemType AS it ON m.ItemTypeId = it.ItemTypeId INNER JOIN
TblCategory AS c ON it.CategoryId = c.CategoryId INNER JOIN
TblBrand AS b ON bB randId = m.BrandId INNER JOIN
TblVendor AS v ON s.VendorId = v.VendorId INNER JOIN
TblAssetCondition AS ac ON ac.AssetConditionId = a.AssetConditionId left JOIN
TblAssetStatus AS ast asAs.AssetStatusId = a.AssetStatusId INNER JOIN
TblCostCenter AS cc ON a.CostCenterId = cc.CostCenterId
LEFT在tbissue上加入TblAssetIssueDet tbissue.AssetId = a.AssetId
在taissue上留下连接TblAssetIssueMst taissue.IssueId = tbissue.IssueId
left join TblDepartment d on d.DepartmentId = taissue.RefId
where
isnull(@ CategoryId,c.CategoryId)= c.CategoryId和
isnull(@ Brandid,b.BrandId)= b.BrandId和
isnull(@ CondtnId,ac.AssetConditionId)= ac.AssetConditionId and
isnull(@ DeptId,d.DepartmentId)= d.DepartmentId
How to pass null to a date time filed where i am taking data between fromdate and todate and also based on department,category etc....
My query as follows:
SELECT a.AssetId, a.SerialNo, a.ServiceTag, a.CostCenterId, a.AssetStatusId, a.AssetConditionId, a.Description, a.AssetEntryDate, a.RefId, a.RefModule, a.LoginId,
a.StoreStockId, a.AssetNo, a.BarCode, a.AssetPict, a.Notes, i.ItemName, m.Model, it.ItemType, c.CategoryName, b.BrandName, ac.AssetCondition, cc.CostCenter,
CASE WHEN taissue.RefId = 0 THEN ''Not Assigned'' WHEN taissue.RefModule = ''D'' THEN
(SELECT Department
FROM TblDepartment
WHERE DepartmentId = taissue.RefId) ELSE
(SELECT PersonName
FROM TblPerson
WHERE PersonId = taissue.RefId) END AS [user], ast.AssetStatus, s.PurchaseRate, s.POInfo, s.WarrantyDate, v.VendorName, sm.PurDate, sm.PONo
FROM TblAsset AS a INNER JOIN
TblStoreStock AS ss ON a.StoreStockId = ss.StoreStockId INNER JOIN
TblStock AS s ON s.StockId = ss.StockId INNER JOIN
TblStoreEntryMaster AS sm ON sm.PurchaseId = s.PurchaseId INNER JOIN
TblItem AS i ON s.ItemId = i.ItemId INNER JOIN
TblModel AS m ON m.ModelId = i.ModelId INNER JOIN
TblIemType AS it ON m.ItemTypeId = it.ItemTypeId INNER JOIN
TblCategory AS c ON it.CategoryId = c.CategoryId INNER JOIN
TblBrand AS b ON b.BrandId = m.BrandId INNER JOIN
TblVendor AS v ON s.VendorId = v.VendorId INNER JOIN
TblAssetCondition AS ac ON ac.AssetConditionId = a.AssetConditionId left JOIN
TblAssetStatus AS ast ON ast.AssetStatusId = a.AssetStatusId INNER JOIN
TblCostCenter AS cc ON a.CostCenterId = cc.CostCenterId
LEFT join TblAssetIssueDet tbissue on tbissue.AssetId=a.AssetId
left join TblAssetIssueMst taissue on taissue.IssueId=tbissue.IssueId
left join TblDepartment d on d.DepartmentId=taissue.RefId
where
isnull(@CategoryId,c.CategoryId) = c.CategoryId and
isnull(@BrandID, b.BrandId) = b.BrandId and
isnull(@CondtnId,ac.AssetConditionId) = ac.AssetConditionId and
isnull(@DeptId,d.DepartmentId) = d.DepartmentId
推荐答案
要将null传递给datetime,请使用nullable:
DateTime? currentDate = null;
To pass null to datetime use nullable:
DateTime? currentDate = null;
这篇关于如何将null传递到日期时间字段,我在fromdate和todate之间以及根据部门,类别等处理数据...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!