Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 19-Apr-13 20:50pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To pass null to datetime use nullable:
 
DateTime? currentDate = null;
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 PIEBALDconsult 110
3 Richard MacCutchan 105
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100