Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

To pass null to datetime use nullable:

DateTime? currentDate = null;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900