Results 1 to 6 of 6

Thread: Pasting Null values in SQL

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    53

    Question Pasting Null values in SQL

    Ok, I'm trying to figure out how to paste a bunch of records from excel to an SQL table. Some fields will contain no data. When I paste into the table, it makes the fields that have no data Null. I set it up so any new records entered in the table and have fields that contain no data will be an empty string. i put a value of "" instead of Null. But when I do paste records it keeps the fields with no data as Null. Is there a way to make anything pasted, imported, or appended not created NULL values for fields that contain no data, either in the table design or within the excel spreadsheet, etc. Thanks in advance for any information.

  2. #2
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Pasting Null values in SQL

    What is wrong with having NULL values in those fields? I use NULLs all the time.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    53

    Re: Pasting Null values in SQL

    Well I'm comparing data lets say between two tables. One column contains fields with data and fields with no data. I try to run a query to match records from 2 different tables. It shows all records that match that have data in every field but excludes any records that match but do have fields that have null values in them. But if I go through and change any no data fields that are null to an empty string using ""...all records that match that has both empty fields and do contain values..show up which i do want.

  4. #4
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Pasting Null values in SQL

    An OUTER JOIN as opposed to an INNER JOIN should bring back all records regardless of whether they are NULL or not.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    53

    Re: Pasting Null values in SQL

    Quote Originally Posted by SeanK
    An OUTER JOIN as opposed to an INNER JOIN should bring back all records regardless of whether they are NULL or not.
    I'll give it a try ...thank you

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Pasting Null values in SQL

    You could also use a function in the SQL to convert Null values to empty strings, whilst leaving non-null values as they are.

    I presume by "SQL table" you actually mean that you are using SQL Server (as opposed to Access/Oracle/MySQL/... which also use the language SQL), in which case you can do it using the IsNull function, eg:
    Code:
    ...
    WHERE IsNull(Table1.FieldA, '') = IsNull(Table2.FieldA, '') 
    ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width