Solved

How do I account for NULL fields?

Posted on 1998-12-18
4
162 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
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
tschill120198 earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Did you get it working?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now