small query issue with regd to varchar conversion

  • i have a table with 4 columns

    name type place

    abc sas tx

    def ds tx

    abc df tx

    .abc dc tx

    .def de tx

    .

    .

    .

    .

    .

    .

    .

    .

    n.ow here what i really want to get the result as

    abc ----3

    def-----2

    total----5

    how can i write a query for that..

    my column --name datatype is varchar with length --8

    select Name ,count(name) from table1

    group by name

    then my answer is

    abc---3

    def---2

    how can i get total with 5 in the output

    when i tried

    select name,sum(name),count(*) form table1

    group by name

    it is giving me error as cannot aggregate varchar when i used cast or convert then it is throwing error as cannot convert varchar to int....

    Thanks,
    Chinna

    Its the Journey which gives you Happiness not the Destination-- Dan Millman

  • Hi Vetran,

    Try below query.

    select isnull(Name,'Total') ,count(name) from table1

    group by name with rollup

    Tariq
    master your setup, master yourself.
    http://mssqlsolutions.blogspot.com

  • select name,count(Name) as num from table1 group by name

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply