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. Database & SysAdmin
  3. Database
  4. SQL Select Where query

SQL Select Where query

Scheduled Pinned Locked Moved Database
helpdatabasequestion
21 Posts 9 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.
  • J Joe Stansfield

    Hi all, Firstly, I must confess to being a very amateur programmer with a lot to learn! However, I'm battling away and am slowly getting my head around things. I have a query I have written which as follows:

    SELECT File_Name
    WHERE (File_Name = @File_Name1)

    File_Name1 is a user input parameter. My problem is that, even if the record does not exist, it returns the record, resulting in an error on the client side. Is it possible to edit that query to return a file_name field value of say, 1, if the searched record doesn't exist? Any help appreciated! (Also for note most of my queries are generated by VStudio, so my understanding of them leaves a lot to be desired...)

    H Offline
    H Offline
    Hitesh R
    wrote on last edited by
    #21

    Try the following query.

    SELECT CASE WHEN COUNT(File_Name)=0 THEN 1 ELSE COUNT(File_Name) END as FileName from tblname
    WHERE (File_Name = @File_Name1)

    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