Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 17th, 2012, 04:07 AM
Registered User
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query to return value/string if no records found

Hi All,
First of all apologies for such question but I consider myself as rookie in creating any kind of queries.
Still - this will definitely help my case so I'd really appreciate your help.
And.. moving back to the point :)

Having following table:
12345 'OFFR' 12
23456 'MSG' 13

I'd like to construct the query which in this particular case would return the REC_CD as 'Record_ID' for REC_TYP='OFFR' where USERID=? (always fetched by the application) and if such USER_ID doesn't exists (for the particular REC_TYP of course) to return string or any other value.
The result for this query in case of user_id 23456 = would be "doesn't exist" or sth for instance 'FALSE' and for 123456 it would be '12'

Many thanks in advance
Old June 24th, 2012, 11:58 AM
Authorized User
Join Date: Oct 2006
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn

If I understand correctly the select statement below should work for you:

THEN'Does Not Exist'
 REC_CD, UserID 
from recTest 
where UserID=?
Strange and crazy, but everything is possible

Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeater Control: No Records Found jumpseatnews ASP.NET 2.0 Basics 9 August 29th, 2007 04:19 PM
Filtering GridView Records Using a Query String Yubmat BOOK: Beginning ASP.NET 2.0 and Databases 5 November 1st, 2006 09:03 PM
Return from different records in same table rodmcleay SQL Language 2 October 10th, 2005 08:51 PM
Display 0 when no records found in a query awwhite Access VBA 1 December 2nd, 2004 03:39 PM
Query to return 37 records maha Access 3 September 10th, 2004 02:37 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.