Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-07-10 : 10:47:18
|
HI AllAnother question for you guys, (My mind gone blank today)What i want to do is count how many times the [Omnipay_Account] column is populated with a number per parentid. In the [Omnipay_Account] column you can either have a null or a 15 digit numberIdea result layout would be three columns these columns would be Every row, would need to be grouped via the parentid numberParentId Omnipay MSIPMy query is SELECT [ParentID] ,[Omnipay_Account] FROM [FDMS].[dbo].[Dim_Outlet] |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-10 : 10:56:22
|
you need to use COUNTsomething likeSELECT [ParentID],COUNT([Omnipay_Account]) AS CntFROM [FDMS].[dbo].[Dim_Outlet]GROUP BY [ParentID] ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-07-10 : 10:58:20
|
Illustration with the help of data would make it easier for all so always appreciated if you could provide sample data. you can use count function as following SELECT ParentId,Count(Omnipay_Account)From [FDMS].[dbo].[Dim_Outlet]WHERE Omnipay_Account IS NOT NULL --if you're looking for only records where this field is populatedGroup by ParentIdCheersMIK |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-10 : 11:00:24
|
Reading again you're asking for 3 columns in outputso it can be even thisSELECT [ParentID],[Omnipay_Account],COUNT([Omnipay_Account]) OVER (PARTITION BY [ParentID]) AS CntFROM [FDMS].[dbo].[Dim_Outlet] ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|