Solved

How do I account for NULL fields?

Posted on 1998-12-18
4
202 Views
Last Modified: 2010-03-19
How do I break this up so if the gsATASuffix is NULL abandon and run (line 1) then go to the Else section?  If gsATASuffix in NOT Null continue on...I have written this so many different ways that I cannot see the solution anymore.

msSQL = "SELECT " & gsATAPrefix & "+ '-' +" & gsATABase

msSQL = msSQL & "+ '-' +" & gsATASuffix & " AS Expr1 From " & gsTBL_ATAInfo & " WHERE " & gsPartIndex & " = " & _
mlPartIndex & " And Not IsNull(" & gsATASuffix & ") Group By " & gsATAPrefix & "+ '-' +" & gsATABase & "+'-'+" & gsATASuffix & ";"

Else

msSQL = msSQL & " AS Expr1 From " & gsTBL_ATAInfo & " WHERE " & gsPartIndex & " = " & _
mlPartIndex & " Group By " & gsATAPrefix & "+ '-' +" & gsATABase & ";"

End If

0
Comment
Question by:kmdisney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
tschill120198 earned 200 total points
ID: 1092332
Looks like you are doing this in VBScript, and that gsATASuffix is a string.  If by "gsATASuffix is NULL" you mean an empty string, this should work...

Or do you literally mean NULL?  Let me know if I've misunderstood your question...

msSQL = "SELECT " & gsATAPrefix & "+ '-' +" & gsATABase
If Len(gstaSuffix) = 0 then
    msSQL = msSQL & "+ '-' +" & gsATASuffix & " AS Expr1 From " & gsTBL_ATAInfo & " WHERE " & gsPartIndex & " = " & _
    mlPartIndex & " And Not IsNull(" & gsATASuffix & ") Group By " & gsATAPrefix & "+ '-' +" & gsATABase & "+'-'+" & gsATASuffix & ";"
Else
    msSQL = msSQL & " AS Expr1 From " & gsTBL_ATAInfo & " WHERE " & gsPartIndex & " = " & _
    mlPartIndex & " Group By " & gsATAPrefix & "+ '-' +" & gsATABase & ";"
End If
0
 

Author Comment

by:kmdisney
ID: 1092333
I am using VB 6 and literally the siffix column is NULL but I could set it to zero length.

In the meantime I will try your suggestion.


0
 

Author Comment

by:kmdisney
ID: 1092334
Nope - same problem...

See  the msSQL on line 3 basically says take the Prefix and the Base and go find the matching suffix using the gsPartIndex. Which when the suffix exists I return a string like XX-XXX-XXX.  The problem is IF the suffix is indeed NULL the code will NOT jump to the ELSE...The ELSE gives me just the correct Prefix and Base with no suffix.  Does this make sense?  What I need this to do is to take the prefix and base and see if there is a suffix - if there is continue on...if not just return the prefix and base.
Complicated huh?

msSQL = "SELECT " & gsATAPrefix & "+ '-' +" & gsATABase
If Len(gsATASuffix) = 0 Then
msSQL = msSQL & "+ '-' +" & gsATASuffix & " AS Expr1 From " & gsTBL_ATAInfo & " WHERE " & gsPartIndex & " = " & _
            mlPartIndex & " And Not IsNull(" & gsATASuffix & ") Group By " & gsATAPrefix & "+ '-' +" & gsATABase & "+'-'+" & gsATASuffix & ";"

            Else
            msSQL = msSQL & " AS Expr1 From " & gsTBL_ATAInfo & " WHERE " & gsPartIndex & " = " & _
            mlPartIndex & " Group By " & gsATAPrefix & "+ '-' +" & gsATABase & ";"
0
 
LVL 2

Expert Comment

by:tschill120198
ID: 1092335
Did you get it working?
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

717 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