Click here to Skip to main content
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 5: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 1

  Permalink  
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 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 329
2 CPallini 260
3 DamithSL 214
4 Maciej Los 197
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 3 May 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