How to insert Null, after selecting values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Girish Kanakagiri
    New Member
    • May 2007
    • 93

    How to insert Null, after selecting values

    I have 2 tables. TabA and TabAdup

    both table structure is same. I executed a select query (with some condition) on TabA & fetched the values to local variables.

    Then I ran insert query to TabAdup with values from local variables.

    These are carried out in a for loop for all the values

    Here there are 8 column have structure as NULL ALLOWED.(NOT NULL - is not there)
    During insertion for any of these 8 columns when their value is NULL, insert is not happening properly.

    In both the table definition, I have not given default value but still it is inserted with 0 when the original value is null. I want exact insertion if null then that column should have null in TabAdup.

    I cannot have so many insert statements by removing the null field from insert statement because the combinations will come 2 power 8 = 1024 insert statements.

    Please clarify/resolve.

    Code has to be in PRO C/ C Sharp
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    How come you're doing the inserts one at a time in code instead of using SQL? Is there a reason you can't use insert into?
    Code:
    INSERT INTO TabADup
    SELECT ...
    FROM TabA

    Comment

    • Girish Kanakagiri
      New Member
      • May 2007
      • 93

      #3
      Actually the select statement is at one function & the insert statement is another function. In the insert function before insert statement fetch is executed to populate the values to local variables & then by these local variables, insertion is done in the loop for every record.
      Actually after select query execution before insertion some more tasks are performed & that's why both these things are separated by presenting them in different functions.
      So now how can we avoid this 0 insertion from local variable when null is the value for the column in original table?

      Comment

      • PsychoCoder
        Recognized Expert Contributor
        • Jul 2010
        • 465

        #4
        If I'm understanding your question why not pass DbNull.Value when you know the value will be null. If you pass and empty string that's not going to translate to NULL in your table

        Comment

        • Girish Kanakagiri
          New Member
          • May 2007
          • 93

          #5
          Hi Richard, What you are saying is correct but I am using Unix OS & not windows & thus tell me what should i include to make this DbNull working at this environment?

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Show us the code.

            Comment

            Working...