Click here to Skip to main content
11,575,882 members (55,556 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
How to list all data in one table in sql join query ...I am binding assetid,assetstatus etc based on category as the following sql query:
SELECT    a.AssetStatusId, s.AssetStatus, COUNT(*) as [Assets] from TblAssetStatus s
left join TblAsset a on a.AssetStatusId = s.AssetStatusId
INNER JOIN  dbo.TblStoreStock ON a.StoreStockId = dbo.TblStoreStock.StoreStockId
INNER JOIN  dbo.TblStock ON dbo.TblStoreStock.StockId = dbo.TblStock.StockId
INNER JOIN  dbo.TblItem ON dbo.TblStock.ItemId = dbo.TblItem.ItemId
INNER JOIN dbo.TblModel ON dbo.TblItem.ModelId = dbo.TblModel.ModelId
INNER JOIN dbo.TblIemType ON dbo.TblModel.ItemTypeId = dbo.TblIemType.ItemTypeId
INNER JOIN dbo.TblCategory ON dbo.TblIemType.CategoryId = dbo.TblCategory.CategoryId
where TblCategory.CategoryId='1'
 group by a.AssetStatusId, s.AssetStatus

I want to show all asset status even if the category condtn isn't having it...How to do the same...
Posted 2-May-13 4:12am
Comments
CHill60 at 2-May-13 13:52pm
   
Try replacing the inner join with a left outer join http://msdn.microsoft.com/en-us/library/ms187518(v=SQL.105).aspx[^]
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this...
SELECT    a.AssetStatusId, s.AssetStatus, COUNT(*) as [Assets] from TblAssetStatus s
left join TblAsset a on a.AssetStatusId = s.AssetStatusId
INNER JOIN  dbo.TblStoreStock ON a.StoreStockId = dbo.TblStoreStock.StoreStockId
INNER JOIN  dbo.TblStock ON dbo.TblStoreStock.StockId = dbo.TblStock.StockId
INNER JOIN  dbo.TblItem ON dbo.TblStock.ItemId = dbo.TblItem.ItemId
INNER JOIN dbo.TblModel ON dbo.TblItem.ModelId = dbo.TblModel.ModelId
INNER JOIN dbo.TblIemType ON dbo.TblModel.ItemTypeId = dbo.TblIemType.ItemTypeId
Left JOIN dbo.TblCategory ON dbo.TblIemType.CategoryId = dbo.TblCategory.CategoryId
--where TblCategory.CategoryId='1'
 group by a.AssetStatusId, s.AssetStatus
Happy Coding!
Smile | :)
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 390
1 Dave Kreskowiak 204
2 F-ES Sitecore 135
3 OriginalGriff 125
4 Abhinav S 98
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 400
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 3 May 2013
Copyright © CodeProject, 1999-2015
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