Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. select top 50

select top 50

Scheduled Pinned Locked Moved Database
databasesql-serversysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thomasa
    wrote on last edited by
    #1

    I have a sql string that gets the top 50 items in a search. Shomthing like: string SQL = "SELECT TOP 50 U.strName " + "FROM tbUser U " + "WHERE U.strName LIKE '%om%' " DataManager dm = new DataManager(); DataTable table = dm.GetDataTable(SQL); but I also want to find exact how many there are. My result would be something like "There are 387 names with the searchstring 'om' here are the top 50: ...." Can this be done with the "SELECT TOP" statement. I'm using MS SQL Server 2000. Thanks Thomas -- modified at 13:15 Friday 20th January, 2006

    M M 2 Replies Last reply
    0
    • T thomasa

      I have a sql string that gets the top 50 items in a search. Shomthing like: string SQL = "SELECT TOP 50 U.strName " + "FROM tbUser U " + "WHERE U.strName LIKE '%om%' " DataManager dm = new DataManager(); DataTable table = dm.GetDataTable(SQL); but I also want to find exact how many there are. My result would be something like "There are 387 names with the searchstring 'om' here are the top 50: ...." Can this be done with the "SELECT TOP" statement. I'm using MS SQL Server 2000. Thanks Thomas -- modified at 13:15 Friday 20th January, 2006

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      You can always run a second query - "SELECT Count(*) From tbUser WHERE ... " - in your search procedure, and return that count with the results.

      1 Reply Last reply
      0
      • T thomasa

        I have a sql string that gets the top 50 items in a search. Shomthing like: string SQL = "SELECT TOP 50 U.strName " + "FROM tbUser U " + "WHERE U.strName LIKE '%om%' " DataManager dm = new DataManager(); DataTable table = dm.GetDataTable(SQL); but I also want to find exact how many there are. My result would be something like "There are 387 names with the searchstring 'om' here are the top 50: ...." Can this be done with the "SELECT TOP" statement. I'm using MS SQL Server 2000. Thanks Thomas -- modified at 13:15 Friday 20th January, 2006

        M Offline
        M Offline
        Muhammad Javed Khan
        wrote on last edited by
        #3

        Try this "SELECT TOP 50 U.strName , (Select Count(*) From tbUser) as TotalRecords " + "FROM tbUser U " + "WHERE U.strName LIKE '%om%' " Regards

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups