Showing posts with label row. Show all posts
Showing posts with label row. Show all posts

Friday, March 23, 2012

Import flat file data

Hi,

I wanted to know if there was a way to import data from a flat file without specifiying the delimiters. I want to import each line in one row so that i can use the substring function to break of the data as an when i want and not as per the delimited format file or the wizard.

i.e if row one had "abc"|"1453"|"Jack"|"Smith"| etc.... rather than importing these as different columns and rows. I want this all in one row, one column.

Is it Possible?

Hi,

You should use the bcp utility with the default -t switch. The default field terminator is the tab. I did not try this, but it should work.

Regards,

Janos

|||

You want to concatenate the data then - just use a "fixed width" as long as the string you want to make. You'll get the quotes as well.

To remove the quotes and add a new delimter at the same time, you could use the "sed" program or something like it to form the text file the way you want it.

|||

what's the "sed" program? and also if i use the wizard and it didn't have a CR or LF then it would throw an error which why I wanted to know if i could import the data via a script? if so how?

|||

"what's the "sed" program? and also if i use the wizard and it didn't have a CR or LF then it would throw an error which why I wanted to know if i could import the data via a script? if so how?"

The sed program is an open-source string processor. There's stuff about it all over the web. I didn't realize that you were using a wizard. There are other methods for import, and you might start here for more ways to do that:

http://search.live.com/results.aspx?q=import+data+%22SQL+Server%22&src=IE-SearchBox

|||

Use BULK INSERT statement to insert each line as one column for one row on temp table.

And then split each row data by the pipe delimiter for separate column.

Doing that you can verify the column data before insert into data table

Wednesday, March 21, 2012

Import Excel

SQL 2k, sp4
Using DTS, I'm trying to import an Excel file. The file is essentially a
report exported into Excel. I have a title in Row A1, some blank rows, then
headings starting in Row 11. Col A - K contain data. Col A has the
equivalent of movie titles. When I "preview" during the import process,
there is no data showing up in the rows except for the titles. If I look at
the Excel file in Excel, I see data in each of the cells correctly. If I
save as a csv, I see all the data. Unfortunately, I don't have the option
of saving these files as csv; they must remain as Excel files. Does anyone
have any suggestions for how I can get the data to show up in Excel?
Thanks in advance,
AndreCopy the data from spreadsheet into another blank workbook and name the
worksheet. Create column names for each column and use DTS to import in DTS
map each column in the excel to correspond with the database columns.
"Andre" wrote:

> SQL 2k, sp4
> Using DTS, I'm trying to import an Excel file. The file is essentially a
> report exported into Excel. I have a title in Row A1, some blank rows, th
en
> headings starting in Row 11. Col A - K contain data. Col A has the
> equivalent of movie titles. When I "preview" during the import process,
> there is no data showing up in the rows except for the titles. If I look
at
> the Excel file in Excel, I see data in each of the cells correctly. If I
> save as a csv, I see all the data. Unfortunately, I don't have the option
> of saving these files as csv; they must remain as Excel files. Does anyon
e
> have any suggestions for how I can get the data to show up in Excel?
> Thanks in advance,
> Andre
>
>|||Hi!!! I don't speak english very well, but I believe that the solution to
this problem is in the next page:
http://www.sqldts.com/default.aspx?254
Bye!!!
"Andre" wrote:

> SQL 2k, sp4
> Using DTS, I'm trying to import an Excel file. The file is essentially a
> report exported into Excel. I have a title in Row A1, some blank rows, th
en
> headings starting in Row 11. Col A - K contain data. Col A has the
> equivalent of movie titles. When I "preview" during the import process,
> there is no data showing up in the rows except for the titles. If I look
at
> the Excel file in Excel, I see data in each of the cells correctly. If I
> save as a csv, I see all the data. Unfortunately, I don't have the option
> of saving these files as csv; they must remain as Excel files. Does anyon
e
> have any suggestions for how I can get the data to show up in Excel?
> Thanks in advance,
> Andre
>
>

Monday, March 12, 2012

import data from Excel failed?

Hi,
I needed to import data from an Excel file to a table. The error I got was:
Error during Transformation 'DirectCopyXform' for Row number 4. Errors
encountered so far in this task: 1. TransformCopy
'DirectCopyXform' conversion error: Destination does not allow NULL on
column pair 1 (source column 'University ID' (DBTYPE_WSTR),
destination column 'universityid' (DBTYPE_STR)).
The university ID is of txt type in Excel. The universityid in SQL is of
varchar(9) and cannot by NULL.
Here is what I did. In EM, I selected All Tasks->Import Data..., then
selected Microsoft Excel 97-2000 as data source and MS SQL server as
destination. But when I clicked Preview to see how data in Excel was mapped
to the table, I noticed the universityid column is empty for some entries.
But their university ID cell is not empty in Excel. They just don't have
that tiny green arrow at the left upper coner of the cell as other Universit
y
IDs that are mapped fine in the import data preview. What might be the
problem and how should I fix?
Thanks in advance for any help.
BingI don't know Why it happens. It happens to me all the time. But you can
work around it.
Save the file as "Text (Tab delimited)" in execl then load the text file to
SQL server.
Regards,
Saravanan
"bing" <bing@.discussions.microsoft.com> wrote in message
news:BBBB27AB-8F68-45C6-812F-30386273CB44@.microsoft.com...
> Hi,
> I needed to import data from an Excel file to a table. The error I got
> was:
> Error during Transformation 'DirectCopyXform' for Row number 4. Errors
> encountered so far in this task: 1. TransformCopy
> 'DirectCopyXform' conversion error: Destination does not allow NULL on
> column pair 1 (source column 'University ID' (DBTYPE_WSTR),
> destination column 'universityid' (DBTYPE_STR)).
> The university ID is of txt type in Excel. The universityid in SQL is of
> varchar(9) and cannot by NULL.
> Here is what I did. In EM, I selected All Tasks->Import Data..., then
> selected Microsoft Excel 97-2000 as data source and MS SQL server as
> destination. But when I clicked Preview to see how data in Excel was
> mapped
> to the table, I noticed the universityid column is empty for some
> entries.
> But their university ID cell is not empty in Excel. They just don't have
> that tiny green arrow at the left upper coner of the cell as other
> University
> IDs that are mapped fine in the import data preview. What might be the
> problem and how should I fix?
> Thanks in advance for any help.
> Bing|||"Saravanan Palanivelu" wrote:

> I don't know Why it happens. It happens to me all the time. But you can
> work around it.
> Save the file as "Text (Tab delimited)" in execl then load the text file t
o
> SQL server.
>
Thanks very much for the quick response and most import the tip, Saravanan.
It works great. The only inconvenience is the wizard for importing data fro
m
text does not provide a way to skip, say, the last <number> of lines. For
some reason, the last several lines in my input text file have all 'NULL's
which I want them to be skipped. It can only skip if you know the line
number first.
Bing

import data from Excel failed?

Hi,
I needed to import data from an Excel file to a table. The error I got was:
Error during Transformation 'DirectCopyXform' for Row number 4. Errors
encountered so far in this task: 1. TransformCopy
'DirectCopyXform' conversion error: Destination does not allow NULL on
column pair 1 (source column 'University ID' (DBTYPE_WSTR),
destination column 'universityid' (DBTYPE_STR)).
The University ID is of txt type in Excel. The universityid in SQL is of
varchar(9) and cannot by NULL.
Here is what I did. In EM, I selected All Tasks->Import Data..., then
selected Microsoft Excel 97-2000 as data source and MS SQL server as
destination. But when I clicked Preview to see how data in Excel was mapped
to the table, I noticed the universityid column is empty for some entries.
But their University ID cell is not empty in Excel. They just don't have
that tiny green arrow at the left upper coner of the cell as other University
IDs that are mapped fine in the import data preview. What might be the
problem and how should I fix?
Thanks in advance for any help.
BingI don't know Why it happens. It happens to me all the time. But you can
work around it.
Save the file as "Text (Tab delimited)" in execl then load the text file to
SQL server.
Regards,
Saravanan
"bing" <bing@.discussions.microsoft.com> wrote in message
news:BBBB27AB-8F68-45C6-812F-30386273CB44@.microsoft.com...
> Hi,
> I needed to import data from an Excel file to a table. The error I got
> was:
> Error during Transformation 'DirectCopyXform' for Row number 4. Errors
> encountered so far in this task: 1. TransformCopy
> 'DirectCopyXform' conversion error: Destination does not allow NULL on
> column pair 1 (source column 'University ID' (DBTYPE_WSTR),
> destination column 'universityid' (DBTYPE_STR)).
> The University ID is of txt type in Excel. The universityid in SQL is of
> varchar(9) and cannot by NULL.
> Here is what I did. In EM, I selected All Tasks->Import Data..., then
> selected Microsoft Excel 97-2000 as data source and MS SQL server as
> destination. But when I clicked Preview to see how data in Excel was
> mapped
> to the table, I noticed the universityid column is empty for some
> entries.
> But their University ID cell is not empty in Excel. They just don't have
> that tiny green arrow at the left upper coner of the cell as other
> University
> IDs that are mapped fine in the import data preview. What might be the
> problem and how should I fix?
> Thanks in advance for any help.
> Bing|||"Saravanan Palanivelu" wrote:
> I don't know Why it happens. It happens to me all the time. But you can
> work around it.
> Save the file as "Text (Tab delimited)" in execl then load the text file to
> SQL server.
>
Thanks very much for the quick response and most import the tip, Saravanan.
It works great. The only inconvenience is the wizard for importing data from
text does not provide a way to skip, say, the last <number> of lines. For
some reason, the last several lines in my input text file have all 'NULL's
which I want them to be skipped. It can only skip if you know the line
number first.
Bing