SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 10th, 2001, 12:22 PM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
How to concatenate field names ?

<i><b>Originally posted by : Padmaja Tallavajhala (coolpersona@hotmail.com)</b></i><br />I have this query that pulls the names of all the patients.<br /><br />SELECT Patient.oid, Person.last_name + ' , ' + Person.first_name + ' ' + Person.middle_name<br /> AS Patient_Name <br />FROM Patient INNER JOIN<br /> Person ON Patient.oid = Person.oid<br />order by Patient_Name<br /><br />But I get several rows where the Patient_Name Alias has null values because the Patient.Middle_Name is null. When we contatenate three fields where one field is null, then does the result also return a null value ? It looks like it does.<br /><br />So to prevent this, what should I do ?<br />

Reply With Quote
  #2  
Old July 31st, 2001, 03:04 PM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
<i><b>Originally posted by : Graham Masters (graham_masters@hp.com)</b></i><br />NULL means "not known" so when ever a NULL value is combined with a known values via math or string operations the result is "not known" or NULL.<br /><br />To solve, use a CASE stmt in your SELECT e.g.<br /><br />SELECT ... +<br />CASE WHEN Person.middle_name IS NULL THEN "" ELSE<br /> " " + Person.middle_name END ... FROM<br /><br /><br />Graham<br /><br /><br />------------<br />Padmaja Tallavajhala at 7/10/2001 10:22:29 AM<br /><br />I have this query that pulls the names of all the patients.<br /><br />SELECT Patient.oid, Person.last_name + ' , ' + Person.first_name + ' ' + Person.middle_name<br /> AS Patient_Name <br />FROM Patient INNER JOIN<br /> Person ON Patient.oid = Person.oid<br />order by Patient_Name<br /><br />But I get several rows where the Patient_Name Alias has null values because the Patient.Middle_Name is null. When we contatenate three fields where one field is null, then does the result also return a null value ? It looks like it does.<br /><br />So to prevent this, what should I do ?<br />

Reply With Quote
  #3  
Old September 21st, 2001, 12:58 AM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
<i><b>Originally posted by : Deepu (medeepu@rediffmail.com)</b></i><br />Hi padmaja<br /><br />You can change the Query as follows, using ISNULL function..it is cool and easy.<br /><br />SELECT Patient.oid, PatientName = ISNULL(Person.last_name,'')+''+ISNULL(Person.middl e_name,'') + ''+ISNULL(Person.first_name,'') FROM Patient INNER JOIN<br />Person ON Patient.oid = Person.oid<br />order by Patient_Name<br /><br /><br /><br /><br />SELECT ... +<br />CASE WHEN Person.middle_name IS NULL THEN "" ELSE<br /> " " + Person.middle_name END ... FROM<br /><br /><br />Graham<br /><br /><br />------------<br />Padmaja Tallavajhala at 7/10/2001 10:22:29 AM<br /><br />I have this query that pulls the names of all the patients.<br /><br />SELECT Patient.oid, Person.last_name + ' , ' + Person.first_name + ' ' + Person.middle_name<br /> AS Patient_Name <br />FROM Patient INNER JOIN<br /> Person ON Patient.oid = Person.oid<br />order by Patient_Name<br /><br />But I get several rows where the Patient_Name Alias has null values because the Patient.Middle_Name is null. When we contatenate three fields where one field is null, then does the result also return a null value ? It looks like it does.<br /><br />So to prevent this, what should I do ?<br />

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > How to concatenate field names ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway