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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Check if record exists

Check if record exists

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasetoolsquestion
2 Posts 2 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.
  • S Offline
    S Offline
    shapper
    wrote on last edited by
    #1

    Hello, I created the following SQL script to check if a record exists: IF (EXISTS (SELECT LevelName FROM dbo.by27_Levels WHERE LOWER(@LevelName) = LOWER(LevelName))) Return (1) ELSE Return (0) And I also found in a web page another solution: IF EXISTS(SELECT 1 FROM TABLENAME WHERE LevelName=@LevelName) SELECT 1 ELSE SELECT 0 - Which approach should I use? - Why "SELECT 1 FROM"? - And when should I use SELECT or RETURN? All I need is to know if the record exists ... nothing else. I will use this procedure on an ASP.NET 2.0 / C# web site. I am not sure if this important but anyway ... Thank You, Miguel

    A 1 Reply Last reply
    0
    • S shapper

      Hello, I created the following SQL script to check if a record exists: IF (EXISTS (SELECT LevelName FROM dbo.by27_Levels WHERE LOWER(@LevelName) = LOWER(LevelName))) Return (1) ELSE Return (0) And I also found in a web page another solution: IF EXISTS(SELECT 1 FROM TABLENAME WHERE LevelName=@LevelName) SELECT 1 ELSE SELECT 0 - Which approach should I use? - Why "SELECT 1 FROM"? - And when should I use SELECT or RETURN? All I need is to know if the record exists ... nothing else. I will use this procedure on an ASP.NET 2.0 / C# web site. I am not sure if this important but anyway ... Thank You, Miguel

      A Offline
      A Offline
      Alexandru Lungu
      wrote on last edited by
      #2

      Second approach; Select 1 is used to minimize the processor workload (there is no need to return the fields) you could also consider: SELECT count(*) AS Results FROM dbo.by27_Levels WHERE LOWER(@LevelName) = LOWER(LevelName)

      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