473,414 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

how do I return a default record if result set is empty

Hello all,
I am working on a sitemap provider for a web site and want to return a default value for a visitors 'zone' if their detected country is not defined as belonging to any particular zone. I am completely new to SQL and have been trying for days so I would really apreciate any help you can offer.

this is where I have got to and although it executes (small cause for celabration)
when I try and use it in a aspx I get and error. I'm not sure if this is the right aproach, it's just what I am trying. Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. DECLARE 
  2. @nodetreeByCountry int,
  3. @nodetreeByDefault int
  4.  
  5. SELECT @nodetreeByCountry =
  6.     'SELECT    siteZone.nodeTreeID
  7. FROM         zoneCountry INNER JOIN
  8.                       siteZone ON zoneCountry.zoneID = siteZone.zoneID INNER JOIN
  9.                       siteDNS INNER JOIN
  10.                       DNS ON siteDNS.DNSID = DNS.DNSID ON siteZone.siteID = siteDNS.siteID
  11. WHERE     (DNS.DomainName = @domainName) AND (zoneCountry.countryISOCode = @countryISOCode)'
  12. SELECT @nodetreeByDefault =
  13.     'SELECT    siteZone.nodeTreeID
  14. FROM         zoneCountry INNER JOIN
  15.                       siteZone ON zoneCountry.zoneID = siteZone.zoneID INNER JOIN
  16.                       siteDNS INNER JOIN
  17.                       DNS ON siteDNS.DNSID = DNS.DNSID ON siteZone.siteID = siteDNS.siteID
  18. WHERE     siteZone.isDefaultZone'
  19. SELECT ISNULL(@nodetreeByCountry,@nodetreeByDefault)
  20.  
Jun 30 '07 #1
1 1717
Vidhura
99
Hello all,
I am working on a sitemap provider for a web site and want to return a default value for a visitors 'zone' if their detected country is not defined as belonging to any particular zone. I am completely new to SQL and have been trying for days so I would really apreciate any help you can offer.

this is where I have got to and although it executes (small cause for celabration)
when I try and use it in a aspx I get and error. I'm not sure if this is the right aproach, it's just what I am trying. Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. DECLARE 
  2. @nodetreeByCountry int,
  3. @nodetreeByDefault int
  4.  
  5. SELECT @nodetreeByCountry =
  6.     'SELECT    siteZone.nodeTreeID
  7. FROM         zoneCountry INNER JOIN
  8.                       siteZone ON zoneCountry.zoneID = siteZone.zoneID INNER JOIN
  9.                       siteDNS INNER JOIN
  10.                       DNS ON siteDNS.DNSID = DNS.DNSID ON siteZone.siteID = siteDNS.siteID
  11. WHERE     (DNS.DomainName = @domainName) AND (zoneCountry.countryISOCode = @countryISOCode)'
  12. SELECT @nodetreeByDefault =
  13.     'SELECT    siteZone.nodeTreeID
  14. FROM         zoneCountry INNER JOIN
  15.                       siteZone ON zoneCountry.zoneID = siteZone.zoneID INNER JOIN
  16.                       siteDNS INNER JOIN
  17.                       DNS ON siteDNS.DNSID = DNS.DNSID ON siteZone.siteID = siteDNS.siteID
  18. WHERE     siteZone.isDefaultZone'
  19. SELECT ISNULL(@nodetreeByCountry,@nodetreeByDefault)
  20.  
Hi
Try this
Expand|Select|Wrap|Line Numbers
  1. DECLARE 
  2. @nodetreeByCountry int,
  3. @nodetreeByDefault int
  4.  
  5. SET @nodetreeByCountry =
  6.     (SELECT    siteZone.nodeTreeID
  7. FROM         zoneCountry INNER JOIN
  8.                       siteZone ON zoneCountry.zoneID = siteZone.zoneID INNER JOIN
  9.                       siteDNS INNER JOIN
  10.                       DNS ON siteDNS.DNSID = DNS.DNSID ON siteZone.siteID = siteDNS.siteID
  11. WHERE     (DNS.DomainName = @domainName) AND (zoneCountry.countryISOCode = @countryISOCode))
  12. SET @nodetreeByDefault =
  13.     (SELECT    siteZone.nodeTreeID
  14. FROM         zoneCountry INNER JOIN
  15.                       siteZone ON zoneCountry.zoneID = siteZone.zoneID INNER JOIN
  16.                       siteDNS INNER JOIN
  17.                       DNS ON siteDNS.DNSID = DNS.DNSID ON siteZone.siteID = siteDNS.siteID
  18. WHERE     siteZone.isDefaultZone)
  19. SELECT ISNULL(@nodetreeByCountry,@nodetreeByDefault)
  20.  
Jul 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mark | last post by:
I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this: if (isset($_POST)) { if ($_POST ==...
11
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
17
by: Gabriel Mejía | last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may intermittently return empty recordsets on queries that should be returning valid results. At the time the problem...
7
by: shikn | last post by:
I wrote one simple piece of codes to test const objects in C++ as below: ================================= class Empty{}; main() { const Empty e1; } ==================================
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
1
by: David | last post by:
Hi, I have a problem with returning a value from an external function..... My asp page is basically a list taken from a database. A date record is written from the DB, then all the...
12
by: Matt B | last post by:
I was just wondering if there is a "best" choice from the following couple of ways of returning a value from a method: 1) private HashAlgorithm GetSpecificHashAlgorithm(string hashString){ if...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.