Showing posts with label sheet. Show all posts
Showing posts with label sheet. Show all posts

Tuesday, March 27, 2012

DTS question - need your help!

I am trying to use DTS load Excel data to SQL Server

The Excel Spreadsheet has 100 columns in each row. Let say I have 3 rows in Excel sheet.
Each row has 100 columns as follows,

column1, column2, ...column100

Now I want to load it to a table which has only one column.

The first record will be the column1 of the first row from the excel spreadsheet
The second record will be the column2 of the first row from the excel spreadsheet
...
The 100th record will be the column100 of the first row from the excel spreadsheet

The 101th record will be the column1 of the second row from the excel spreadsheet
...

Can anyone give me a suggections? Thanks in advance,

PeterHmm, any way you can transpose the columns in Excel? I can't think of a simple way to create an SQL Statement to transpose the columns in DTS. It might be easier to manipulate Excel, rather than trying to do the transpose in DTS.|||I agree with the first post, but you could do it starting with DTS. Suck the excel sheet into a 'holding' table and then run a stored procedure that takes each cell and makes it a record by itself. You could use a cursor to step through the records and do 100 inserts to the final table for each row in the holding table.|||Is the order truyly that important?

You can get all the data in one column by using the following SQL statement instead of a table as your source:

SELECT Column1
FROM [Sheet1$]
UNION ALL
SELECT Column2
FROM [Sheet1$]
UNION ALL
SELECT Column3
FROM [Sheet1$]
...

You'll need a lot of cut and past (or a handy little script) to generate all the UNIONed selects.

If the order truly is important, then I'd add another column to your spreadsheet for the row number. Import the entire spreadsheet into the a temp table using something like this:

SELECT TheValue = Column1,
TheRow = RowNumber, -- your row number column
TheColumn = 1
FROM [Sheet1$]
UNION ALL
...

Increment the column number for each column. Again, a script will write this monster select for you. Then you can insert into your final table:

INSERT ...
SELECT TheValue
FROM MyTempImportTable
ORDER by TheRow ASC, TheColumn ASC

FYI - You may need to use UNION rather than UNION ALL. I don't recall the exact workings of EXCEL with respect to the ALL part. A little experimenting (or a syntax) error should clear it up pretty quickly.

Sunday, March 25, 2012

DTS problem

Hi,
I am trying to export data into EXCEL sheet using DTS, It is working fine
for single user, however it fails with error messages when tried by multiple
users at the same time...So is it limitation of DTS as it does not run
simultaneously ?Is the destination Excel Workbook the same for all users?
If it is, then that's why the DTS package fails. If that's not the case,
please post the actual error message.
ML|||Hi ML,
It is the same excel but user can change the path and each one is exporting
it in different folders, so I feel it should not be the case.
Errors is shown like :
"Microsoft Database Engine canot open the file ", It is already opened
exculisevely by another user, or you need permission to view data.
Is this because every user is using single user(user name + pwd, is provided
thru config file), with special permission, to fetch data from different
tables.
Thanks
"ML" wrote:

> Is the destination Excel Workbook the same for all users?
> If it is, then that's why the DTS package fails. If that's not the case,
> please post the actual error message.
>
> ML|||Judging by the error message all users are trying to access the same Excel
file.
You say they have the option of changing the output path - at what point in
time are they allowed to change it? Before or after executing the DTS packag
e?
ML|||It is through input box, which is displayed through VB script and that is th
e
part of DTS package. So It happens during the execution of DTS package.
"ML" wrote:

> Judging by the error message all users are trying to access the same Excel
> file.
> You say they have the option of changing the output path - at what point i
n
> time are they allowed to change it? Before or after executing the DTS pack
age?
>
> ML|||If the error occurs before this VB script is executed, then the connection t
o
the Excel file is made before the user selects the output file - which means
the connection is made to the same file for each user.
However, if the error occurs after the user has selected a different output
file, then it seems that the connection is not made to the file the user
selected.
Maybe you could create a new file for each user at the beginning of the
package, and establish a connection dynamically:
1) open a new file using VBS;
2) name the file by embedding the user's name and a timestamp (e.g.
"Output_John_200510301255.xls");
3) passing the filename as a global variable to the data connection.
ML

Tuesday, February 14, 2012

DTS import Excel to SQL Server, keep leading zeroes

Hi,
I have a few DTS packages where I am importing data to SQL Server 2000
tables. There are a couple of fields in the Excel sheet where data has
leading zeroes (zip code fields). It seems that somewhere during the
DTS import, the leading zeroes are lost and the data is inserted to the
tables without those zeroes. I have the Excel sheet fields set up as
"Special" cell type and selected the "Zip Code" type (which keeps the
leading zeroes). Is there a way to keep those leading zeroes somehow
during the import?
I thought of saving the Excel file as .csv file, but would that make
any difference? I actually tried that already and it seems that the
leading zeroes are lost already in the Excel saving phase, when I
re-open the .csv file in Excel, the leading zeroes are gone.
Any tips are greatly appreciated.
Thanks,
Tuomas
Tuomas
How have you stored the data in Excel file?
I did some testing as 00013' data to be transfered into SQL Server table
(varchar(10) column). I works fine.
"Tuomas" <tuomaskesti@.hotmail.com> wrote in message
news:1121084389.185595.217280@.g44g2000cwa.googlegr oups.com...
> Hi,
> I have a few DTS packages where I am importing data to SQL Server 2000
> tables. There are a couple of fields in the Excel sheet where data has
> leading zeroes (zip code fields). It seems that somewhere during the
> DTS import, the leading zeroes are lost and the data is inserted to the
> tables without those zeroes. I have the Excel sheet fields set up as
> "Special" cell type and selected the "Zip Code" type (which keeps the
> leading zeroes). Is there a way to keep those leading zeroes somehow
> during the import?
> I thought of saving the Excel file as .csv file, but would that make
> any difference? I actually tried that already and it seems that the
> leading zeroes are lost already in the Excel saving phase, when I
> re-open the .csv file in Excel, the leading zeroes are gone.
> Any tips are greatly appreciated.
> Thanks,
> Tuomas
>
|||Hi,
The data in Excel is in "Special" cell type (if you right click a cell
and select "Format cells") and under "Special" there is a "Type" "Zip
code". Did you try that in your tests or how did you store the data in
your cell? If I just open a new Excel sheet and type 00013 in a cell
and then move away from that cell, the leading zeroes are gone right
away.
I did some more testing myself and had three different columns in an
Excel sheet, all where I stored the same zip code 00013. But in the
first column, I left the cell type ("General") as it is when I created
the new sheet. For the second column, I changed the cell type to
"Special -> zip code" as I mention above. And for the third column, I
left the cell type ("General") as it was when I created the new sheet
but I put a quotation mark before the data as in: '00013. I generated a
new DTS package and ran it. The import went through without any
problems. In the destination table I have three columns, all the same
data type (varchar(10)). For the first two columns, the leading zeroes
disappeared, but for the third, where the quotation mark is before the
data in the cell, the leading zeroes were in the SQL Server table after
the import. So, it seems that the "Special -> zip code" does not mean
anything in terms of keeping the zeroes during the import even though
the zeroes are shown fine in Excel. I tried also the "Custom" cell type
in Excel and forced the leading zeroe(s) for the zip codes where zero
was the first number so that the zip code would always be a five digit
number. But in this case also, the zeroes disappeared during the
import.
Now, if this is the case that the leading zeroes are only kept if the
data in Excel is stored with the quotation mark before the actual data,
I guess I need to do an Excel function to put the quotation mark before
all the zip code data or something like that...
If you have any further info, please let me know.
Thanks,
Tuomas

DTS import Excel to SQL Server, keep leading zeroes

Hi,
I have a few DTS packages where I am importing data to SQL Server 2000
tables. There are a couple of fields in the Excel sheet where data has
leading zeroes (zip code fields). It seems that somewhere during the
DTS import, the leading zeroes are lost and the data is inserted to the
tables without those zeroes. I have the Excel sheet fields set up as
"Special" cell type and selected the "Zip Code" type (which keeps the
leading zeroes). Is there a way to keep those leading zeroes somehow
during the import?
I thought of saving the Excel file as .csv file, but would that make
any difference? I actually tried that already and it seems that the
leading zeroes are lost already in the Excel saving phase, when I
re-open the .csv file in Excel, the leading zeroes are gone.
Any tips are greatly appreciated.
Thanks,
TuomasTuomas
How have you stored the data in Excel file?
I did some testing as 00013' data to be transfered into SQL Server table
(varchar(10) column). I works fine.
"Tuomas" <tuomaskesti@.hotmail.com> wrote in message
news:1121084389.185595.217280@.g44g2000cwa.googlegroups.com...
> Hi,
> I have a few DTS packages where I am importing data to SQL Server 2000
> tables. There are a couple of fields in the Excel sheet where data has
> leading zeroes (zip code fields). It seems that somewhere during the
> DTS import, the leading zeroes are lost and the data is inserted to the
> tables without those zeroes. I have the Excel sheet fields set up as
> "Special" cell type and selected the "Zip Code" type (which keeps the
> leading zeroes). Is there a way to keep those leading zeroes somehow
> during the import?
> I thought of saving the Excel file as .csv file, but would that make
> any difference? I actually tried that already and it seems that the
> leading zeroes are lost already in the Excel saving phase, when I
> re-open the .csv file in Excel, the leading zeroes are gone.
> Any tips are greatly appreciated.
> Thanks,
> Tuomas
>|||Hi,
The data in Excel is in "Special" cell type (if you right click a cell
and select "Format cells") and under "Special" there is a "Type" "Zip
code". Did you try that in your tests or how did you store the data in
your cell? If I just open a new Excel sheet and type 00013 in a cell
and then move away from that cell, the leading zeroes are gone right
away.
I did some more testing myself and had three different columns in an
Excel sheet, all where I stored the same zip code 00013. But in the
first column, I left the cell type ("General") as it is when I created
the new sheet. For the second column, I changed the cell type to
"Special -> zip code" as I mention above. And for the third column, I
left the cell type ("General") as it was when I created the new sheet
but I put a quotation mark before the data as in: '00013. I generated a
new DTS package and ran it. The import went through without any
problems. In the destination table I have three columns, all the same
data type (varchar(10)). For the first two columns, the leading zeroes
disappeared, but for the third, where the quotation mark is before the
data in the cell, the leading zeroes were in the SQL Server table after
the import. So, it seems that the "Special -> zip code" does not mean
anything in terms of keeping the zeroes during the import even though
the zeroes are shown fine in Excel. I tried also the "Custom" cell type
in Excel and forced the leading zeroe(s) for the zip codes where zero
was the first number so that the zip code would always be a five digit
number. But in this case also, the zeroes disappeared during the
import.
Now, if this is the case that the leading zeroes are only kept if the
data in Excel is stored with the quotation mark before the actual data,
I guess I need to do an Excel function to put the quotation mark before
all the zip code data or something like that...
If you have any further info, please let me know.
Thanks,
Tuomas

DTS import Excel to SQL Server, keep leading zeroes

Hi,
I have a few DTS packages where I am importing data to SQL Server 2000
tables. There are a couple of fields in the Excel sheet where data has
leading zeroes (zip code fields). It seems that somewhere during the
DTS import, the leading zeroes are lost and the data is inserted to the
tables without those zeroes. I have the Excel sheet fields set up as
"Special" cell type and selected the "Zip Code" type (which keeps the
leading zeroes). Is there a way to keep those leading zeroes somehow
during the import?
I thought of saving the Excel file as .csv file, but would that make
any difference? I actually tried that already and it seems that the
leading zeroes are lost already in the Excel saving phase, when I
re-open the .csv file in Excel, the leading zeroes are gone.
Any tips are greatly appreciated.
Thanks,
TuomasTuomas
How have you stored the data in Excel file?
I did some testing as 00013' data to be transfered into SQL Server table
(varchar(10) column). I works fine.
"Tuomas" <tuomaskesti@.hotmail.com> wrote in message
news:1121084389.185595.217280@.g44g2000cwa.googlegroups.com...
> Hi,
> I have a few DTS packages where I am importing data to SQL Server 2000
> tables. There are a couple of fields in the Excel sheet where data has
> leading zeroes (zip code fields). It seems that somewhere during the
> DTS import, the leading zeroes are lost and the data is inserted to the
> tables without those zeroes. I have the Excel sheet fields set up as
> "Special" cell type and selected the "Zip Code" type (which keeps the
> leading zeroes). Is there a way to keep those leading zeroes somehow
> during the import?
> I thought of saving the Excel file as .csv file, but would that make
> any difference? I actually tried that already and it seems that the
> leading zeroes are lost already in the Excel saving phase, when I
> re-open the .csv file in Excel, the leading zeroes are gone.
> Any tips are greatly appreciated.
> Thanks,
> Tuomas
>|||Hi,
The data in Excel is in "Special" cell type (if you right click a cell
and select "Format cells") and under "Special" there is a "Type" "Zip
code". Did you try that in your tests or how did you store the data in
your cell? If I just open a new Excel sheet and type 00013 in a cell
and then move away from that cell, the leading zeroes are gone right
away.
I did some more testing myself and had three different columns in an
Excel sheet, all where I stored the same zip code 00013. But in the
first column, I left the cell type ("General") as it is when I created
the new sheet. For the second column, I changed the cell type to
"Special -> zip code" as I mention above. And for the third column, I
left the cell type ("General") as it was when I created the new sheet
but I put a quotation mark before the data as in: '00013. I generated a
new DTS package and ran it. The import went through without any
problems. In the destination table I have three columns, all the same
data type (varchar(10)). For the first two columns, the leading zeroes
disappeared, but for the third, where the quotation mark is before the
data in the cell, the leading zeroes were in the SQL Server table after
the import. So, it seems that the "Special -> zip code" does not mean
anything in terms of keeping the zeroes during the import even though
the zeroes are shown fine in Excel. I tried also the "Custom" cell type
in Excel and forced the leading zeroe(s) for the zip codes where zero
was the first number so that the zip code would always be a five digit
number. But in this case also, the zeroes disappeared during the
import.
Now, if this is the case that the leading zeroes are only kept if the
data in Excel is stored with the quotation mark before the actual data,
I guess I need to do an Excel function to put the quotation mark before
all the zip code data or something like that...
If you have any further info, please let me know.
Thanks,
Tuomas