Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 February 23rd, 2008, 12:08 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default Working around DB Nulls

I've built a database table with standard FirstName & LastName columns. I'm calling it into a dynamic page using SELECT [FirstName] + " " + [LastName] AS Name ORDER BY LastName. Everything working fine, until my client needs to insert a company name instead of an persons name. Since the results are ordered by LastName, the best sorting scheme is to list the company name as the last name. But then when it's displayed to the page FirstName = NULL, and the result of concatenating that is also NULL.

How can I deal with companies so that they are easy to insert, orders alphabetically with people's last names, and displays on the page?

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old February 23rd, 2008, 12:13 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Do something like this:

SELECT
  ISNULL(FirstName, '') + " " + ISNULL(LastName, '') as Name
FROM
  [Table]

This will prevent the NULL value from being returned.
hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 27th, 2008, 03:11 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Thanks!

It helped a lot more once I realized it was comma empty string not comma double quote. ;)

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
IN and NULLs joxa83 SQL Server 2005 8 September 29th, 2008 03:03 AM
MS OLE DB Provider for ODBC -not working 4 me humour General .NET 6 August 3rd, 2004 03:19 AM
looking for nulls Warbird C# 4 July 1st, 2004 07:50 AM
DB Connection not working XP costrega Classic ASP Databases 7 November 11th, 2003 06:18 AM
Working with Access DB stu9820 ASP.NET 1.0 and 1.1 Basics 2 September 26th, 2003 08:11 AM





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