Solved

How do I account for NULL fields?

Posted on 1998-12-18
4
190 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

821 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