Results 1 to 8 of 8

Thread: Odd SQL Server import problem

  1. #1
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Odd SQL Server import problem

    Sincerely hope a clever hexite can help me out here, as I'm pulling my hair out with this one.

    I have a CSV file. It contains data (well, duh ). A couple of the columns have "missing" data - i.e. blank values. When I load the file into the Import Export wizard (using SQL Server management studio express 2008), and set up all the correct datatype, the data preview clearly shows all the lovely blanks that I expect to be in the file.

    I have created a table to put my data in. It has the two columns that contain blank values set to allow nulls. It had everything set to appropriate data types. I can map the columns during import, and when I preview the data it shows me all my lovely blanks.

    I can successfully import the data into my table.

    Now, perhaps I'm just being naive, but when I import blank values from a CSV into columns which are set to allow nulls, I expect to get null values in the columns. But I'm not - I'm getting zeros. I've checked and there's definitely no default value for those columns, the columns are definitely set to allow nulls, and as I say all the data previews during import show the blank values.

    So, anyone got any idea why SQL server hates me today? I really can't see anything else I can do differently to get this import working...

  2. #2
    Now with added Ruffus Dog Tattysnuc's Avatar
    Join Date
    Feb 2006
    Location
    Liverpool
    Posts
    1,373
    Thanks
    283
    Thanked
    207 times in 133 posts
    • Tattysnuc's system
      • Motherboard:
      • Asus 570X Strix F
      • CPU:
      • 3900X @ Stock
      • Memory:
      • 32Gb Rysen C18 Corsair
      • Storage:
      • 2x 1TB nvme
      • Graphics card(s):
      • 2080 ti under Bykski water
      • PSU:
      • eVGA 850W
      • Case:
      • TT Core 5
      • Operating System:
      • Win 10 Pro
      • Monitor(s):
      • Lg 43"
      • Internet:
      • Utility Warehouse

    Re: Odd SQL Server import problem

    Is it a text field or a number field? If it is an int or double try changing it to a varchar.
    Join the HEXUS Folding @ home team

  3. Received thanks from:

    scaryjim (23-09-2011)

  4. #3
    Anthropomorphic Personification shaithis's Avatar
    Join Date
    Apr 2004
    Location
    The Last Aerie
    Posts
    10,857
    Thanks
    645
    Thanked
    872 times in 736 posts
    • shaithis's system
      • Motherboard:
      • Asus P8Z77 WS
      • CPU:
      • i7 3770k @ 4.5GHz
      • Memory:
      • 32GB HyperX 1866
      • Storage:
      • Lots!
      • Graphics card(s):
      • Sapphire Fury X
      • PSU:
      • Corsair HX850
      • Case:
      • Corsair 600T (White)
      • Operating System:
      • Windows 10 x64
      • Monitor(s):
      • 2 x Dell 3007
      • Internet:
      • Zen 80Mb Fibre

    Re: Odd SQL Server import problem

    The GUI based import does a few things like that depending on datatypes used. It's a pain.

    BCP solves all the issues but a lot of the time it's faster to use the GUI import and then run a cleanup command or two.

    I.e. if you have no zero values, you can update all the zeros to nulls.

    Or, if you are a coder, you can write a little bit of vbscript to handle it for you on the data transfer.
    Main PC: Asus Rampage IV Extreme / 3960X@4.5GHz / Antec H1200 Pro / 32GB DDR3-1866 Quad Channel / Sapphire Fury X / Areca 1680 / 850W EVGA SuperNOVA Gold 2 / Corsair 600T / 2x Dell 3007 / 4 x 250GB SSD + 2 x 80GB SSD / 4 x 1TB HDD (RAID 10) / Windows 10 Pro, Yosemite & Ubuntu
    HTPC: AsRock Z77 Pro 4 / 3770K@4.2GHz / 24GB / GTX 1080 / SST-LC20 / Antec TP-550 / Hisense 65k5510 4K TV / HTC Vive / 2 x 240GB SSD + 12TB HDD Space / Race Seat / Logitech G29 / Win 10 Pro
    HTPC2: Asus AM1I-A / 5150 / 4GB / Corsair Force 3 240GB / Silverstone SST-ML05B + ST30SF / Samsung UE60H6200 TV / Windows 10 Pro
    Spare/Loaner: Gigabyte EX58-UD5 / i950 / 12GB / HD7870 / Corsair 300R / Silverpower 700W modular
    NAS 1: HP N40L / 12GB ECC RAM / 2 x 3TB Arrays || NAS 2: Dell PowerEdge T110 II / 24GB ECC RAM / 2 x 3TB Hybrid arrays || Network:Buffalo WZR-1166DHP w/DD-WRT + HP ProCurve 1800-24G
    Laptop: Dell Precision 5510 Printer: HP CP1515n || Phone: Huawei P30 || Other: Samsung Galaxy Tab 4 Pro 10.1 CM14 / Playstation 4 + G29 + 2TB Hybrid drive

  5. Received thanks from:

    scaryjim (23-09-2011)

  6. #4
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Odd SQL Server import problem

    I ended up sidestepping it in a most ridiculously convoluted way - I used the original SPSS file rather than the CSV export, imported that into Access, that preserved the nulls, then I imported the Access into SQL Server. What a palarver *sigh*

    Tatty: it's all numeric fields. If you try to persuade the import wizard that they're text really and it should convert them, it throws its toys out of the pram about loss of data precision. And whilst I don't necessarily need the fields to be number in the database, it makes a lot more sense of the filtering options etc. if they are. Odd thing is I'm sure I didn't have this problem with the last dataset for this project, but I'm now wondering if I cleared all the nulls out of that one first...

    The big issue with this job was that one of the fields used 0 as a meaningful data item, soit was trashing the meaning of the data, not just the structure *sigh* I have SQL Server sometimes...

  7. #5
    Now with added Ruffus Dog Tattysnuc's Avatar
    Join Date
    Feb 2006
    Location
    Liverpool
    Posts
    1,373
    Thanks
    283
    Thanked
    207 times in 133 posts
    • Tattysnuc's system
      • Motherboard:
      • Asus 570X Strix F
      • CPU:
      • 3900X @ Stock
      • Memory:
      • 32Gb Rysen C18 Corsair
      • Storage:
      • 2x 1TB nvme
      • Graphics card(s):
      • 2080 ti under Bykski water
      • PSU:
      • eVGA 850W
      • Case:
      • TT Core 5
      • Operating System:
      • Win 10 Pro
      • Monitor(s):
      • Lg 43"
      • Internet:
      • Utility Warehouse

    Re: Odd SQL Server import problem

    Quote Originally Posted by scaryjim View Post
    I ended up sidestepping it in a most ridiculously convoluted way - I used the original SPSS file rather than the CSV export, imported that into Access, that preserved the nulls, then I imported the Access into SQL Server. What a palarver *sigh*

    Tatty: it's all numeric fields. If you try to persuade the import wizard that they're text really and it should convert them, it throws its toys out of the pram about loss of data precision. And whilst I don't necessarily need the fields to be number in the database, it makes a lot more sense of the filtering options etc. if they are. Odd thing is I'm sure I didn't have this problem with the last dataset for this project, but I'm now wondering if I cleared all the nulls out of that one first...

    The big issue with this job was that one of the fields used 0 as a meaningful data item, soit was trashing the meaning of the data, not just the structure *sigh* I have SQL Server sometimes...
    I know your pain. I too am banging my head against a wall trying to import an excel spreadsheet in with a simple product hierarchy in it, but I want to save the SSIS package so that the hierarchy, which isn't part of our ERP, can be maintained, and then incorporated into our SSAS database.

    First tried importing it, failed. Wrong datatype, so I put the file on the server as a flat file, with Tabs delimiting. Imported, but cannot change the column names from Column1, column2 etc.

    Version 3 finally imports, and I set the first column to varchar(2), and the rest to Varchar(50), but the import routine cannot find the table, despite choosing and editing the SQL. GRRR. I could really hate MS sometimes....
    Join the HEXUS Folding @ home team

  8. #6
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Odd SQL Server import problem

    s'ok, the other developer here is busy converting all my int's to varchars anyway, on the basis that it takes less storage

    The most amusing thing? He's used nvarchar not varchar, so he is *guaranteed* to use at least as much storage for every field. I need to have serious words about division of labour and not redoing everything someone else does just because it's not how you'd do it...

  9. #7
    Now with added Ruffus Dog Tattysnuc's Avatar
    Join Date
    Feb 2006
    Location
    Liverpool
    Posts
    1,373
    Thanks
    283
    Thanked
    207 times in 133 posts
    • Tattysnuc's system
      • Motherboard:
      • Asus 570X Strix F
      • CPU:
      • 3900X @ Stock
      • Memory:
      • 32Gb Rysen C18 Corsair
      • Storage:
      • 2x 1TB nvme
      • Graphics card(s):
      • 2080 ti under Bykski water
      • PSU:
      • eVGA 850W
      • Case:
      • TT Core 5
      • Operating System:
      • Win 10 Pro
      • Monitor(s):
      • Lg 43"
      • Internet:
      • Utility Warehouse

    Re: Odd SQL Server import problem

    I'm still very much a SQL SVR 2k8 virgin, so that's gone straight over my head. not even sure what an nvarchar is as opposed to a varchar - I should look that up.

    Needless to say, the SSIS package had worked, but my data somehow contained exactly double rows, and that was breaking the primary key rule I'd defined on t he table. I cleaned the data and it's running sweetly now.

    I've also found the location of the SSIS packages that are saved in SQL Server 2008 R2 64bit - dbo.sysssispackages and managed to clean up after myself. Clever me I thought - it's probably in a 101 lesson, but I swear I looked there earlier and couldn't find them!

    Life is good again, just in time for the weekend....
    Join the HEXUS Folding @ home team

  10. #8
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Odd SQL Server import problem

    Good stuff

    nvarchar is unicode, rather than ascii, so takes 2 bytes of storage per character rather than 1. And both nvarchar and varchar use 2 bytes of additional storage to handle the variable length thing. So an nvarchar uses 4 bytes of storage to handle a single character; a varchar uses 4 bytes of storage to handle 2 ASCII characters, and an int uses 4 bytes to store any number up to 2^31ish! So his storage optimisation breaks down for any number larger than 99

    Get stuck in to SQL Server - I whinge about it a lot but it's very powerful, and Microsoft provide some decent tools for working with it. I hate to say it in a lot of ways, but I'm much more productive working with Microsoft technologies than I ever have been working with open source tools.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Battlefield Bad Company 2
    By Namor in forum Gaming
    Replies: 1040
    Last Post: 23-03-2011, 02:54 PM
  2. Odd XP network problem?
    By b0redom in forum Software
    Replies: 2
    Last Post: 10-01-2008, 06:05 PM
  3. Odd sound problem
    By marko in forum PC Hardware and Components
    Replies: 8
    Last Post: 23-12-2005, 04:09 PM
  4. Odd problem
    By Davey in forum Networking and Broadband
    Replies: 15
    Last Post: 24-03-2005, 04:12 PM
  5. Authenticating to Server 2003 - weird problem
    By Richie in forum Software
    Replies: 8
    Last Post: 12-02-2004, 12:55 AM

Posting Permissions

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