Nz

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. I want a query to return
Name (CompanyName)
Name

So, if there is no Company, leave it blank.
However, I'm returning
Name (CompanyName)
Name ()

How can I get rid of the superfluous parentheses? Here's what I have:
Name1: [Name] & nz(" (" & [CompanyName] & ")"," ")
 
Hi,


SELECT [Name] & ( "(" + CompanyName + ")" )
FROM somewhere



Since + propagates the NULL, while & doesn't.


Another alternative, less techno:



SELECT iif( companyName Is NULL, [name], [name] & "(" & companyName &
")" )
FROM somewhere




Hoping it may help,
Vanderghast, Access MVP
 
Stephanie said:
Hello. I want a query to return
Name (CompanyName)
Name

So, if there is no Company, leave it blank.
However, I'm returning
Name (CompanyName)
Name ()

How can I get rid of the superfluous parentheses? Here's what I have:
Name1: [Name] & nz(" (" & [CompanyName] & ")"," ")
[Name] & Iif([CompanyName] is null,"","("&[CompanyName]&"(")

BY putting the "(" in the NZ() you guarentee that it is NOT null.
 
Excellent! I used the first case- thanks for the lesson on "+"
--
Thanks for the help!


Michel Walsh said:
Hi,


SELECT [Name] & ( "(" + CompanyName + ")" )
FROM somewhere



Since + propagates the NULL, while & doesn't.


Another alternative, less techno:



SELECT iif( companyName Is NULL, [name], [name] & "(" & companyName &
")" )
FROM somewhere




Hoping it may help,
Vanderghast, Access MVP


Stephanie said:
Hello. I want a query to return
Name (CompanyName)
Name

So, if there is no Company, leave it blank.
However, I'm returning
Name (CompanyName)
Name ()

How can I get rid of the superfluous parentheses? Here's what I have:
Name1: [Name] & nz(" (" & [CompanyName] & ")"," ")
 
Back
Top