Solved

How do I account for NULL fields?

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why Delete * statement wont work with sql server ? 6 38
Help Required 3 91
T-SQL: "HAVING CASE" Clause 1 23
convert null in sql server 12 31
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

786 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