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

    How to max the datatype char value in sql server

    In database design as follows (table name company)

    Fieldname Data Type
    Compid (primary key) char(10)

    In database record as follows (table name company)
    Compid
    1
    2
    3
    4
    5

    i want to get max value of compid in company table.
    for that how can i write the sql server
  • #761749
    Hi

    Do you want the max id to be retrieved?
    The sql query is as follows.

    Select max(compid)
    from company
    group by compid

    This will get you the highest compid in your table.

    Regards

    Sridhar Thota.
    If you learn't from defeat..
    You haven't really lost..

    Sridhar Thota.
    Editor: DNS Forum.

  • #761751
    Execute the below query to get the maximum value of the Compid column.

    select max(Compid) from Company;

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #761757
    hi

    You can try this Query for max record get


    Select max(Compid) from company1

    Select top 1 from company1 ORDER by Compid desc

    Select max(Compid), ROW_NUMBER()OVER(Order by Compid desc) as id from company1
    group by Compid

    Select top 10 PERCENT * from company1 order by Compid desc


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

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

  • #761761
    Following is your required query

    Select max(Compid) from company1

    you can also use the group functions

    AVG ( [ DISTINCT | ALL ] col ) col = column name The average value of that column
    COUNT ( * ) none Number of rows returned including duplicates and NULLs
    COUNT ( [ DISTINCT | ALL ] col ) col = column name Number of rows where the value of the column is not NULL
    MAX ( [ DISTINCT | ALL ] col ) col = column name Maximum value in the column
    MIN ( [ DISTINCT | ALL ] col ) col = column name Minimum value in the column
    SUM ( [ DISTINCT | ALL ] col ) col = column name Sum of the values in the column
    CORR ( e1, e2 ) e1 and e2 are column names Correlation coefficient between the two columns after eliminating nulls
    MEDIAN ( col ) col = column name Middle value in the sorted column, interpolating if necessary
    STDDEV ( [ DISTINCT | ALL ] col ) col = column name Standard deviation of the column ignoring NULL values
    VARIANCE ( [ DISTINCT | ALL ] col )

    By Nathan
    Direction is important than speed

  • #761768
    Hi,

    This is basic question if you search the same-thing in Google you may find no of links for the same, you can do it in n no of ways.

    EX:

    1) select Max(CompanyID) from Company

    2) select * from
    ( select dense_Rank() Over (order by CompanyID ASC) as Rnk from Company) AS Cmp
    Where Cmp.Rnk=1

    3) Select * from
    (Select Rank() Over (order by CompanyID ASC) as Rnk from Company) AS Cmp
    Where Cmp.Rnk=1


    like above queries you can do it in no of ways.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #761806
    Hello Rao,

    You can use below query :

    SELECT MAX(CompanyID) FROM Company

    Hope this will help you.

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


Sign In to post your comments