SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Count Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 07/10/2013 :  10:47:18  Show Profile  Reply with Quote
HI All

Another 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 number
Idea result layout would be three columns these columns would be
Every row, would need to be grouped via the parentid number
ParentId Omnipay MSIP

My query is

SELECT
[ParentID]
,[Omnipay_Account]
FROM [FDMS].[dbo].[Dim_Outlet]

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 07/10/2013 :  10:56:22  Show Profile  Reply with Quote
you need to use COUNT

something like


SELECT 
[ParentID]
,COUNT([Omnipay_Account]) AS Cnt
FROM [FDMS].[dbo].[Dim_Outlet]
GROUP BY [ParentID]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 07/10/2013 :  10:58:20  Show Profile  Reply with Quote
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 populated
Group by ParentId

Cheers
MIK
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 07/10/2013 :  11:00:24  Show Profile  Reply with Quote
Reading again you're asking for 3 columns in output
so it can be even this


SELECT 
[ParentID]
,[Omnipay_Account]
,COUNT([Omnipay_Account]) OVER (PARTITION BY [ParentID]) AS Cnt
FROM [FDMS].[dbo].[Dim_Outlet]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.24 seconds. Powered By: Snitz Forums 2000