You must Sign In to post a response.
  • Category: SQL Server

    Group By command in sql server 2008

    How to set Group By and Where its use(Group By) very Urgent,

    Code:

    SELECT dbo.product_stk.ProductType, dbo.product_stk.BrandName, ISNULL(dbo.product_stk.prod_stk, 0) - ISNULL(dbo.Sales_Bill_stk.billstk, 0) AS balstock,
    dbo.Sales_Bill_stk.billstk
    FROM dbo.product_stk INNER JOIN
    dbo.Sales_Bill_stk ON dbo.product_stk.BrandName = dbo.Sales_Bill_stk.product
  • #760731
    hi
    kirubakaran

    You can try this code


    Select * from tblemp where empname like '%jo%' group by id,Empno,EmpName


    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #760738
    Hello Kirubaharan,

    Refer the below query for GROUP BY Statement :

    SELECT COUNT(Bundle_NOS), Bundle_Quantity, Record_ID FROM BundleMaking WHERE Transaction_ID = '" + TextBoxTranID.Text + "' GROUP BY Record_ID

    As such you have not provided any data so that we are not clear with your exact requirement.


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #760746
    Group by always used in conjunction with the aggregate functions to group the result-set by one or more columns.
    Here is group by syntax
    SELECT column_name, aggregate_function(column_name)
    FROM table_name
    WHERE column_name operator value
    GROUP BY column_name;
    Here we need 'aggregate_function' each time to run group by clause
    additionally, You can use a WHERE clause in a query containing a GROUP BY clause. Rows not meeting the conditions in the WHERE clause are eliminated before any grouping is done.
    https://technet.microsoft.com/en-us/library/aa213250(v=sql.80).aspx

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #760759
    Hi

    Group by clause is used with aggregate functions such as sum(), avg(),min(),max() and count() etc.

    For example

    Select count(sal) From emp
    where deptno='2'
    Group by empid

    Where clause will check the condition before grouping.

    Regards

    Sridhar Thota.
    "Poverty means.. Poverty of knowledge.."

    Sridhar Thota.
    Editor: DNS Forum.

  • #760887
    Hi
    As Sridar said , Group by is used for the functions like sum,avg etc. we cant use it without these functions.

    Do Good... Enjoy your life.....

  • #761021
    The current query does not use aggregate functions like MAX(), SUM() etc and does not require a group by clause.
    The given query will suffice in the scenario given.

  • #763228
    Hi,

    SELECT dbo.product_stk.ProductType, dbo.product_stk.BrandName, ISNULL(dbo.product_stk.prod_stk, 0) - ISNULL(dbo.Sales_Bill_stk.billstk, 0) AS balstock,
    dbo.Sales_Bill_stk.billstk
    FROM dbo.product_stk INNER JOIN
    dbo.Sales_Bill_stk ON dbo.product_stk.BrandName = dbo.Sales_Bill_stk.product
    Group By

    dbo.product_stk.ProductType, dbo.product_stk.BrandName, ISNULL(dbo.product_stk.prod_stk, 0) - ISNULL(dbo.Sales_Bill_stk.billstk, 0) AS balstock,
    dbo.Sales_Bill_stk.billstk

    having count(*)<1


    Hope this will help

    Regards
    Sriram.R


  • Sign In to post your comments