Solved

Error on nulls with Left Mid() function

Posted on 2011-03-12
7
437 Views
Last Modified: 2012-05-11
this function in Access produces an error on nulls in the column:
Left(Right(,Len()-InStr(),"(")),Len(Right(,Len()-InStr((),"(")))-1) - how can this be rewritten so that it will convert nulls into empty strings?  

Also, will this work in SQL 2005?  thanx
0
Comment
Question by:bar0822
  • 3
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
Andrew_Webster earned 250 total points
ID: 35116239
Use Nz(MyColumn,"").

Nz will work in an Access query of linked SQL Server data.  It will not work in a pass-through query that is evaluated by SQL Server as it's a VBA method, not a SQL method.

In T-SQL you can use ISNULL(MyColumn,"") instead.
0
 
LVL 75
ID: 35117341
I hate to say this, but your expression has many issues.  For starters, your InStr() functions have no arguments ... which is your first issue.  Next, Your Right() function syntax is incorrect.  

Left(Right(,Len()-InStr(),"(")),Len(Right(,Len()-InStr((),"(")))-1)


Left(Right(,Len()-InStr(),"(")),Len(Right(,Len()-InStr((),"(")))-1)

Please look these up in VBA Help to get the correct syntax ...

mx
0
 
LVL 75
ID: 35326011
"bar0822 declined to include the actual strings and/or fields used in the expression and in doing so"
I see. Just to make it a trick question.
0
 
LVL 75
ID: 35326029
@JDettman:
"Nice to see you wanting to go the extra mile here,"
Huh?  Not related.
0
 
LVL 8

Expert Comment

by:Andrew_Webster
ID: 35328105
I agree with everyone!  Yes, the expression is a mess, and a royal pain to debug.  But the question was about how to convert Nulls to empty strings, and that was the answer given.

If I was stuck with that expression, I'd probably write a VBA function to clean it up, and call that from a query.  But even that might depend on the performance, as if it's in a query that hits many rows then performance could be a dog.

But I'm not going to go into "what ifs" or I'd drive myself nuts.  More nuts.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question