Doubt in COUNT(*)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganeshkumar08
    New Member
    • Jan 2008
    • 31

    Doubt in COUNT(*)

    HI SQL Friends

    Can any one you help me please..
    The below is the query

    SELECT COUNT([dbo].[User].[Name]) FROM [dbo].[User]
    WHERE [dbo].[User].[Name]='GaneshKumar' GROUP BY [dbo].[User].[Name] HAVING (COUNT([dbo].[User].[Name]) = 1)

    In the above query the WHERE condition is satisfied then the result will be a integer value. If the codition is not satisfied the no row is returned.

    My problem is, if now row is returned it should return 0 value,

    Can any one help me please

    Thanks
    Ganesh Kumar V
  • jagged
    New Member
    • Feb 2008
    • 23

    #2
    SELECT COUNT(user.name ) FROM Users where .... returns 0 if there are no records.

    I'm not sure if you're trying to do something else, but from the looks of it, you don't need the group by / having at all.

    Comment

    • ganeshkumar08
      New Member
      • Jan 2008
      • 31

      #3
      I tried like below...

      SELECT COUNT(dbo.[user].[name]) FROM dbo.[User] where dbo.[User].[Name]='bb' GROUP BY dbo.[User].[Name]

      The above query returns no record.
      But for me i need to display 0(zero)

      Comment

      • jagged
        New Member
        • Feb 2008
        • 23

        #4
        Originally posted by ganeshkumar08
        I tried like below...

        SELECT COUNT(dbo.[user].[name]) FROM dbo.[User] where dbo.[User].[Name]='bb' GROUP BY dbo.[User].[Name]

        The above query returns no record.
        But for me i need to display 0(zero)

        Don't use GROUP BY

        select count(user.name ) from user where user.name = 'bb'

        that's it. Don't add anything else after

        Comment

        Working...