Showing posts with label fields. Show all posts
Showing posts with label fields. Show all posts

Friday, March 30, 2012

Import RIS format to SQL Server?

Hello!

I have data exported from a Reference Manager 11, and need to import it
into and SQL database.

Each record has different number of fields. It is used to cite journal
articles.
(more about the format at
http://www.adeptscience.co.uk/kb/article/A626)

The format is very strange:

TY - RPRT
A1 - Esparza,J.
T1 - Report of a WHO workshop on the measurement and significance of
neutralizing antibody to HIV and SIV, London, 3-5 October 1988
Y1 - 1990
VL - 4
SP - 269
EP - 275
RP - Not In File
CY - San Francisco CA
PB - UC Berkeley
KW - HIV
KW - SIV
KW - AIDS
T3 - World Health Organisation Global Programme on AIDS
ER -

TY - CHAP
A1 - Franks,L.M.
T1 - Preface by an AIDS Victim
Y1 - 1991
VL - 10
SP - vii
EP - viii
RP - Not In File
T2 - Cancer, HIV and AIDS.
CY - Berkeley CA
PB - Berkeley Press
KW - HIV
KW - AIDS
M1 - 1
M2 - 1
SN - 0-679-40110-5
ER -

TY - CASE
A1 - Cary,A.
A1 - Friedenrich,W.
T1 - Redman v. State of California
Y1 - 1988/10/7
VL - 201
IS - 32
SP - 220
EP - 240
RP - Not In File
CY - ATLA Law Reporter
PB - San Diego County 45th Judicial District, California
KW - AIDS
KW - litigation
KW - AIDS litigation
KW - rape
U1 - ISSN 0456-8125
N1 - Raped inmate can press case against officials for contracting
AIDS
ER -

It looks like some of the columns are separted by CR but part of the
same colum. For instance 'KW' is seen multiple times per record but
should be one field called 'KW'.

Any idea how I would import this to SQL Server with the DTS?"Tmuld" <tmuldoon@.spliced.com> wrote in message
news:1113921439.658252.91360@.g14g2000cwa.googlegro ups.com...
> Hello!
> I have data exported from a Reference Manager 11, and need to import it
> into and SQL database.
> Each record has different number of fields. It is used to cite journal
> articles.
> (more about the format at
> http://www.adeptscience.co.uk/kb/article/A626)
> The format is very strange:

<snip
> It looks like some of the columns are separted by CR but part of the
> same colum. For instance 'KW' is seen multiple times per record but
> should be one field called 'KW'.
> Any idea how I would import this to SQL Server with the DTS?

The format looks rather awkward to handle in DTS transformations, so you'll
probably need some other solution. One would be to load the data into a
staging table, then use stored procedures to clean it up and INSERT it into
the destination tables. A better option is probably to parse the data
outside the database, using C#/Perl or whatever your preferred language is,
then load it. You might be able to transform it into XML, for example, then
use OPENXML or SQLXML Bulk Load to import it:

http://www.sqlxml.org/faqs.aspx?faq=13

Whatever solution you decide on, you could still use a DTS package to manage
all the steps, whether they are stored procedures or external programs.

Simon|||I think that your best bet would be to loop through the file in a VB
application which handles the logic. Usually, files that hold data in a
"record" format have the columns going across the file and rows going
down. They also usually have a set number of columns. While this format
isn't unheard of (I've worked with similar formats in the past) most of
the standard tools for importing files (BCP, DTS, BULK INSERT) are not
designed to deal with it. BCP might be able to get around it if you had
a fixed number of columns, but the variable number of columns would
present a problem there.

If you have no skill in a programming language like VB and you don't
have access to a resource who has those skills then you could BCP the
file into a staging table with an IDENTITY column. Make sure that the
ordering of the records in the file is preserved in the rows of the
table. From there you can loop through the rows sequentially with a
cursor. This is one of those VERY rare instances where I think a cursor
is called for. As I said though, I think you're better off using VB or
something similar if you can.

By looping through the records you can create a new row in your base
table every time that you hit a new record tag in the file then you can
create rows in children tables for each repeatable column type.

Good luck,
-Tom.

Wednesday, March 28, 2012

Import issue for CSV file with quotes around all data fields

Hello!

I have a CSV file that encloses all the data fields with quotation marks. Here is a sample:

"08/01/2007","3","021200012","123","0.03"

Is there any way in SSIS that I can tell the Flat File wizard to ignore the quotation marks? I don't want to import the quotes in the database since that will really mess up other applications that need to use the data.

Thanks in advance,

Harry

I'm running into the same issue. I was going to post and I saw your posting. Though mine is slightly different. I have several fields on my .csv file, some fields have quotes some do not and some data values have quotes and some do not. So my line looks like this:

NISSAN,"NEW", "Smith, John"

or some look like this

NISSAN, NEW, Smith, Michelle

So i need something to remove the quotes as well so I don't see them in my table, only the data

|||

Got the answer...put the " (quotes) in the text qualifier instead of the default of <none>.

|||

Big H wrote:

Got the answer...put the " (quotes) in the text qualifier instead of the default of <none>.

I have that but because not all of my data is surrounded by quotes, its still failing for me on the insert into the table

|||

Hi,

You can put a script component and then clean the fields that you need to clean by using any string methods.

Hope that helps


Cheers

Rizwan

|||

How? I'm new to this SSIS process and I'm learning as I go. So how would a script componet 'clean' the fields?

|||

IGotyourdotnet wrote:

How? I'm new to this SSIS process and I'm learning as I go. So how would a script componet 'clean' the fields?

Isn't all of your "text" data surrounded by quotes? "Proper" CSV formatting would have text fields surrounded by quotes and numeric fields not surrounded by quotes.

If you can, move away as fast as you can from CSV files. It's a terrible format, especially if you run into situations where you have embedded quotes in your text fields. Tab delimited or fixed width are better alternatives. Or even XML.

|||

Phil Brammer wrote:

IGotyourdotnet wrote:

How? I'm new to this SSIS process and I'm learning as I go. So how would a script componet 'clean' the fields?

Isn't all of your "text" data surrounded by quotes? "Proper" CSV formatting would have text fields surrounded by quotes and numeric fields not surrounded by quotes.

If you can, move away as fast as you can from CSV files. It's a terrible format, especially if you run into situations where you have embedded quotes in your text fields. Tab delimited or fixed width are better alternatives. Or even XML.

Isn't all of your "text" data surrounded by quotes? No, its generated by another process (I believe an Oracle process)and the SSIS (former DTS) packages grabs the files and inserts the data into the SQL tables.

|||

IGotyourdotnet wrote:


Isn't all of your "text" data surrounded by quotes? No, its generated by another process (I believe an Oracle process)and the SSIS (former DTS) packages grabs the files and inserts the data into the SQL tables.

But *some* of your text data has quotes?|||

correct, it could be all of it at times or some of it at times. So I could see it like

row 1 NISSAN, Smith John, "NEW"

row 2 NISSAN, "Smith Michelle", NEW

or

row 1 "NISSAN", "Smith John", NEW

row 2 "NISSAN", Smith John, NEW

or

row 1 "NISSAN", "Smith" John, NEW"

row 2 "NISSAN", "Smith John", "NEW"

so far I've see all of the above in this file.

|||

You should be able to use a Derived Column transform to strip the quotes off.

Code Snippet

REPLACE([Column 0],"\"","")

Monday, March 26, 2012

Import from MySQL db adds padding in CHAR (Text) fields

I'm moving a small application from a MySQL db to MSSQL2K and using the Import feature of SQL2K. The db in question is simple, only three tables, mostly text (CHAR) fields. The problem is that when I examine the field contents I find that the unused cha
racter positions within the fields have been padded with trailing spaces. (Example: original 10 char field containing "ABC" now contains "ABC ". Application not happy. I've tried a number of options in the Import wizard (ansi padding etc) and it
seems to have had no effect. Any ideas? Solutions? KB articles?
Thanks for ANY help.
-J
By definition, a char(10) is always padded with spaces up to the length of the datatype. This is why we call
char a fixed length datatype. If you want a variable length datatype, use varchar.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"JManton" <anonymous@.discussions.microsoft.com> wrote in message
news:D89560CC-AAAB-459C-A039-8073C17EB2ED@.microsoft.com...
> I'm moving a small application from a MySQL db to MSSQL2K and using the Import feature of SQL2K. The db in
question is simple, only three tables, mostly text (CHAR) fields. The problem is that when I examine the
field contents I find that the unused character positions within the fields have been padded with trailing
spaces. (Example: original 10 char field containing "ABC" now contains "ABC ". Application not happy.
I've tried a number of options in the Import wizard (ansi padding etc) and it seems to have had no effect.
Any ideas? Solutions? KB articles?
> Thanks for ANY help.
> -J
|||That was it. I guess there are a few diffs between MySQL and MSSQL. I also had to tweak the recordID field and use IDENTITY attribute. Thanks for the quick reply and on-the-mark-help.
-J

Import from MySQL db adds padding in CHAR (Text) fields

I'm moving a small application from a mysql db to MSSQL2K and using the Impo
rt feature of SQL2K. The db in question is simple, only three tables, mostl
y text (CHAR) fields. The problem is that when I examine the field contents
I find that the unused cha
racter positions within the fields have been padded with trailing spaces. (E
xample: original 10 char field containing "ABC" now contains "ABC ".
Application not happy. I've tried a number of options in the Import wizar
d (ansi padding etc) and it
seems to have had no effect. Any ideas? Solutions? KB articles?
Thanks for ANY help.
-JBy definition, a char(10) is always padded with spaces up to the length of t
he datatype. This is why we call
char a fixed length datatype. If you want a variable length datatype, use va
rchar.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"JManton" <anonymous@.discussions.microsoft.com> wrote in message
news:D89560CC-AAAB-459C-A039-8073C17EB2ED@.microsoft.com...
> I'm moving a small application from a mysql db to MSSQL2K and using the Import fea
ture of SQL2K. The db in
question is simple, only three tables, mostly text (CHAR) fields. The probl
em is that when I examine the
field contents I find that the unused character positions within the fields
have been padded with trailing
spaces. (Example: original 10 char field containing "ABC" now contains "ABC
". Application not happy.
I've tried a number of options in the Import wizard (ansi padding etc) and i
t seems to have had no effect.
Any ideas? Solutions? KB articles?
> Thanks for ANY help.
> -J|||That was it. I guess there are a few diffs between mysql and MSSQL. I also
had to tweak the recordID field and use IDENTITY attribute. Thanks for the
quick reply and on-the-mark-help.
-J

Import from MySQL db adds padding in CHAR (Text) fields

I'm moving a small application from a MySQL db to MSSQL2K and using the Import feature of SQL2K. The db in question is simple, only three tables, mostly text (CHAR) fields. The problem is that when I examine the field contents I find that the unused character positions within the fields have been padded with trailing spaces. (Example: original 10 char field containing "ABC" now contains "ABC ". Application not happy. I've tried a number of options in the Import wizard (ansi padding etc) and it seems to have had no effect. Any ideas? Solutions? KB articles?
Thanks for ANY help.
-JBy definition, a char(10) is always padded with spaces up to the length of the datatype. This is why we call
char a fixed length datatype. If you want a variable length datatype, use varchar.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"JManton" <anonymous@.discussions.microsoft.com> wrote in message
news:D89560CC-AAAB-459C-A039-8073C17EB2ED@.microsoft.com...
> I'm moving a small application from a MySQL db to MSSQL2K and using the Import feature of SQL2K. The db in
question is simple, only three tables, mostly text (CHAR) fields. The problem is that when I examine the
field contents I find that the unused character positions within the fields have been padded with trailing
spaces. (Example: original 10 char field containing "ABC" now contains "ABC ". Application not happy.
I've tried a number of options in the Import wizard (ansi padding etc) and it seems to have had no effect.
Any ideas? Solutions? KB articles?
> Thanks for ANY help.
> -J

Wednesday, March 21, 2012

Import Errors from MS Access

I encountered errors while importing tables from an Access. The only tbales
that errored had date/time fields and it seems SQL didn't like them. The tab
les work just fine in Access so I'm surprised SQL didn't like them. Anyone s
ee this before?Alan,
Most likely cause: MS Access supports dates as early as Jan 1, 100, while
SQL Server only supports dates back to Jan 1, 1753. You probably have a date
prior to Jan 1, 1753. Before you dismiss this idea, keep in mind that a
simple data entry error can morph Jul 15, 1999 to Jul 15, 199 :-)
Use an Access query to locate dates earlier than Jan 1, 1753.
Chief Tenaya
"Alan Fisher" <anonymous@.discussions.microsoft.com> wrote in message
news:838D8D52-BB99-416A-A4D2-4781DCE7040F@.microsoft.com...
> I encountered errors while importing tables from an Access. The only
tbales that errored had date/time fields and it seems SQL didn't like them.
The tables work just fine in Access so I'm surprised SQL didn't like them.
Anyone see this before?|||On Tue, 23 Mar 2004 16:01:06 -0800, "Alan Fisher"
<anonymous@.discussions.microsoft.com> wrote:
Different versions of Access have different levels of support for
upsizing. Try with Access XP or 2003.
When push comes to shov, it's not so hard to build those few tables
yourself, and write append queries to copy over the data.
-Tom.

>I encountered errors while importing tables from an Access. The only tbales that er
rored had date/time fields and it seems SQL didn't like them. The tables work just f
ine in Access so I'm surprised SQL didn't like them. Anyone see this before?

Import directory structure to table

I need to be able to import a directory file list into a sql table.
i.e. table contains fields for filename, date etc...
is this possible?
thanks?absolutely. you are going to have to use file system objects with sp_OACreate. A solution was posted here a long time ago but the thread may have been lost when the server crashed.|||absolutely. you are going to have to use file system objects with sp_OACreate. A solution was posted here a long time ago but the thread may have been lost when the server crashed.

Nah...

http://weblogs.sqlteam.com/brettk/archive/2005/06/28/6895.aspx|||That lastone works Brett, but I can't get it to traverse sub-directories

what I am trying to do is index a hard drive of images for a real estate database.|||Drawback of letting SQL Server do this is that the directory must be on de server of SQL has to have access to remote locations.

My first instinct would have been to write a vbs-script (with a filesystemobject and ado connection) that scans the directories and inserts them in the table. This script could be run from any computer that has network access to the SQL Server.|||Lexiflex, the SQL server has access to the iages via a maped drive.

We will use this to link the image to the realtor, the listing and image history. The idea is that we want to be able to take image submissions, identify if there already are images for the property, if not add it to the listing, if there is add a flag to the listing indicating a change etc...

there is another app run from a web page that automatically places the images in the folder, and names, numbers them appropriatly|||So it should be possible to do this in SQL server.

Just curious: How do you identify which newly found image belongs to what property? And do you keep the images on the filesystem or do you import them in the database?|||The images are named with the ListingID#, and are stored in the file system.|||Good luck with this project! It's always fun to build something and see it at work afterwards. :)|||well, just iterate through the Directory table until @.@.ROWCOUNT = 0

Monday, March 12, 2012

Import Data from Text file

I am importing data from a text file. The file is simple, only 9 fields.
Each field has quotation marks around the data. During the import it
creates a table with varchar fields and length of 8000!!
The only problem with this is that I merge this data and other inforation to
a permenant table with normal field sizes. With this I start getting errors
that the data will be truncated.
Second problem. The code below:
--
Declare @.TableName nvarchar(10)
Declare @.SQLCmd nvarchar(1000)
set @.TableName = 'RS201'
Set @.SQLCmd = '
Insert Into MasterJobLog
(RSID,
Code,
DateStamp,
DocumentName,
Pages,
Cost,
Client,
PatronID,
Printer,
DocumentType)
Select '+ Char(39)+ @.TableName + char(39) + ' ,
replace(Code,Char(34),Null),
replace(DateStamp,Char(34),Null),
replace(DocumentName,Char(34),Null),
replace(Pages,Char(34),Null),
replace(Cost,Char(34),Null),
replace(Client,Char(34),Null),
replace(PatronID,Char(34),Null),
replace(Printer,Char(34),Null),
replace(DocumentType,Char(34),Null)
From ' + @.TableName
print @.Sqlcmd
--
The code produces:
Insert Into MasterJobLog
(RSID,
Code,
DateStamp,
DocumentName,
Pages,
Cost,
Client,
PatronID,
Printer,
DocumentType)
Select 'RS201' ,
replace(Code,Char(34),Null),
replace(DateStamp,Char(34),Null),
replace(DocumentName,Char(34),Null),
replace(Pages,Char(34),Null),
replace(Cost,Char(34),Null),
replace(Client,Char(34),Null),
replace(PatronID,Char(34),Null),
replace(Printer,Char(34),Null),
replace(DocumentType,Char(34),Null)
From RS201
This works with the Print statement.
However when used with the Execute statement, I get:
---
Server: Msg 203, Level 16, State 2, Line 31
The name '
Insert Into MasterJobLog
(RSID,
Code,
DateStamp,
DocumentName,
Pages,
Cost,
Client,
PatronID,
Printer,
DocumentType)
Select 'RS201' ,
replace(Code,Char(34),Null),
replace(DateStamp,Char(34),Null),
replace(DocumentName,Char(34),Null),
replace(Pages,Char(34),Null),
replace(Cost,Char(34),Null),
replace(Client,Char(34),Null),
replace(P...
---
It truncates the SQL string.
Any Ideas!
ArthurI have the solution.
Apparently the contructed SQL command is to long for the execute to handle
with one variable. The on-line books said to break it up into 2 variables
and concatenate the 2 command strings. Thus, Execute (@.Sqlcmd1 + @.SQLCmd2).
This works! So I think that the 8000 byte field size is affecting this.
"Arthur C" <arthur.christy@.tamut.edu.delete.me> wrote in message
news:OaWJoJ$lDHA.2424@.TK2MSFTNGP10.phx.gbl...
> I am importing data from a text file. The file is simple, only 9 fields.
> Each field has quotation marks around the data. During the import it
> creates a table with varchar fields and length of 8000!!
> The only problem with this is that I merge this data and other inforation
to
> a permenant table with normal field sizes. With this I start getting
errors
> that the data will be truncated.
> Second problem. The code below:
> --
> Declare @.TableName nvarchar(10)
> Declare @.SQLCmd nvarchar(1000)
> set @.TableName = 'RS201'
> Set @.SQLCmd = '
> Insert Into MasterJobLog
> (RSID,
> Code,
> DateStamp,
> DocumentName,
> Pages,
> Cost,
> Client,
> PatronID,
> Printer,
> DocumentType)
> Select '+ Char(39)+ @.TableName + char(39) + ' ,
> replace(Code,Char(34),Null),
> replace(DateStamp,Char(34),Null),
> replace(DocumentName,Char(34),Null),
> replace(Pages,Char(34),Null),
> replace(Cost,Char(34),Null),
> replace(Client,Char(34),Null),
> replace(PatronID,Char(34),Null),
> replace(Printer,Char(34),Null),
> replace(DocumentType,Char(34),Null)
> From ' + @.TableName
> print @.Sqlcmd
> --
> The code produces:
> Insert Into MasterJobLog
> (RSID,
> Code,
> DateStamp,
> DocumentName,
> Pages,
> Cost,
> Client,
> PatronID,
> Printer,
> DocumentType)
> Select 'RS201' ,
> replace(Code,Char(34),Null),
> replace(DateStamp,Char(34),Null),
> replace(DocumentName,Char(34),Null),
> replace(Pages,Char(34),Null),
> replace(Cost,Char(34),Null),
> replace(Client,Char(34),Null),
> replace(PatronID,Char(34),Null),
> replace(Printer,Char(34),Null),
> replace(DocumentType,Char(34),Null)
> From RS201
> This works with the Print statement.
> However when used with the Execute statement, I get:
> ---
> Server: Msg 203, Level 16, State 2, Line 31
> The name '
> Insert Into MasterJobLog
> (RSID,
> Code,
> DateStamp,
> DocumentName,
> Pages,
> Cost,
> Client,
> PatronID,
> Printer,
> DocumentType)
> Select 'RS201' ,
> replace(Code,Char(34),Null),
> replace(DateStamp,Char(34),Null),
> replace(DocumentName,Char(34),Null),
> replace(Pages,Char(34),Null),
> replace(Cost,Char(34),Null),
> replace(Client,Char(34),Null),
> replace(P...
> ---
> It truncates the SQL string.
>
> Any Ideas!
> Arthur
>

Import data from excel sheet to ms sql server table

How to import data from excel sheet to ms sql table the data in the excel is the one which is exported from oracle, few data fields of the ms sql server are of int type and few are of varchar, how can I Import data into sql server 2000 with out getting any errors?

It would be helpful if any one can reply (step wise). Thanks in advance. :)

Quote:

Originally Posted by Purvi

How to import data from excel sheet to ms sql table the data in the excel is the one which is exported from oracle, few data fields of the ms sql server are of int type and few are of varchar, how can I Import data into sql server 2000 with out getting any errors?

It would be helpful if any one can reply (step wise). Thanks in advance. :)


What errors are you recving?? You could format the xls sheet to be text, then convert it to whatever you need in MSSQL using DTS. Hope that helps|||The following are the steps to be followd.

1.copy the data from the existing excel sheet to a new excel sheet and save it.
2. Use DTS service and transfer data to a sql server table. For example the table is created with name like sheet1$. Just rename it and change the datatypes of columns in the design mode as you like.
3.when ever you change data from excel to a table, if you get error simple follow the 1 step.

Import Data from Excel problem

I got a table which got over 50 fields from an excel files.
Now I can import them into a temp.dbf file . I found that the field type
defined as nvarchar 255.
I use SP to write a insert these data to another real table. (some field is
char20, . 50. 20...etc)
The problem is As I run the insert statment .I will got [String or binary
data would be truncated] <-- error
I don't want to modify the structure of temp.dbf.
Any method that I can ignore That error and import the data ?
Thanks
you can put 'trims' around the fields in your select
look up ltrim and rtrim in BOL
"Agnes" <agnes@.dynamictech.com.hk> wrote in message
news:u43g$QvLFHA.732@.TK2MSFTNGP12.phx.gbl...
>I got a table which got over 50 fields from an excel files.
> Now I can import them into a temp.dbf file . I found that the field type
> defined as nvarchar 255.
> I use SP to write a insert these data to another real table. (some field
> is char20, . 50. 20...etc)
> The problem is As I run the insert statment .I will got [String or binary
> data would be truncated] <-- error
> I don't want to modify the structure of temp.dbf.
> Any method that I can ignore That error and import the data ?
> Thanks
>

Friday, March 9, 2012

Import Data and Identity fields

When i run the "Import Data" task from SQL 2005 Managment Studio and select the "Copy data from one or more tables or views" option, I notice the task does not re-create the "Identity" field definitions on the destination table. (SQL 2000 EM did this.) Is there a way to tell the import task to include the identity field definition when creating the destiination tables?

The only work around i've found in SQL Mgmt Studio takes multiple steps:

1) run Generate scripts on the source database, and select all tables to create the table scripts (this includes the identity field on each table)

2) run the script on the destination database to created the tables

3) run the import task, edit mappings and select "enable identity insert".

this is really a pain since i could accomplish this all in 1 step in SQL 2000 EM.

Any suggestions? Please help!

Microsoft? You there? Anybody?|||

You might get more traction on this in the SSIS forum, but I'll give it a try. By the way, this is an all-volunteer forum, so if you need immediate support, see http://microsoft.com/support. It's not only us Microsoft working folks in here, we just maintain the forum and try to help as much as we can.

This series of posts might help:

http://www.developerdotstar.com/community/node/727#comment-8456

Basically it involves the "FAST LOAD" option.

Buck Woody

SQL Server Team

Import Data and Identity fields

When i run the "Import Data" task from SQL 2005 Managment Studio and select the "Copy data from one or more tables or views" option, I notice the task does not re-create the "Identity" field definitions on the destination table. (SQL 2000 EM did this.) Is there a way to tell the import task to include the identity field definition when creating the destiination tables?

The only work around i've found in SQL Mgmt Studio takes multiple steps:

1) run Generate scripts on the source database, and select all tables to create the table scripts (this includes the identity field on each table)

2) run the script on the destination database to created the tables

3) run the import task, edit mappings and select "enable identity insert".

this is really a pain since i could accomplish this all in 1 step in SQL 2000 EM.

Any suggestions? Please help!

Microsoft? You there? Anybody?|||

You might get more traction on this in the SSIS forum, but I'll give it a try. By the way, this is an all-volunteer forum, so if you need immediate support, see http://microsoft.com/support. It's not only us Microsoft working folks in here, we just maintain the forum and try to help as much as we can.

This series of posts might help:

http://www.developerdotstar.com/community/node/727#comment-8456

Basically it involves the "FAST LOAD" option.

Buck Woody

SQL Server Team

import data

We have a database in sql server. Now in the front end, we have two fields called latefee and latefeeDateReceived. When next time the people get another late fee. They just replace the old one and enter the new one. But now we want to keep all the history. Keep whatever they get the late fee. I am thing maybe need to create another table called latefee to contain these value. Is is good idea? As later they may want to get a report for all the late fee in one company. The thing is, I need to retrieve the current latefee and latefeeDateReceived and import to latefee table. But I need to create primary key for the latefee table. How can I import? Only one thing is I can import the data first, then add primary key. If I import later, how can I import. (Explain, the data retrieved have fields called CID, Latefee, latefeeDataReceived. But the table latefee has four fields called, lateID, CID, Latefee, latefeeDateReceived. When I import, it is always failed. Anybody can give me an idea? Many thanks.We have a database in sql server. Now in the front end, we have two fields called latefee and latefeeDateReceived. When next time the people get another late fee. They just replace the old one and enter the new one. But now we want to keep all the history. Keep whatever they get the late fee. I am thing maybe need to create another table called latefee to contain these value. Is is good idea? As later they may want to get a report for all the late fee in one company. The thing is, I need to retrieve the current latefee and latefeeDateReceived and import to latefee table. But I need to create primary key for the latefee table. How can I import? Only one thing is I can import the data first, then add primary key. If I import later, how can I import. (Explain, the data retrieved have fields called CID, Latefee, latefeeDataReceived. But the table latefee has four fields called, lateID, CID, Latefee, latefeeDateReceived. When I import, it is always failed. Anybody can give me an idea? Many thanks.

I think you want to create a trigger (or maybe a couple of triggers). I think you would wind up with something like:

CREATE Table DDL:

CREATE TABLE LateFee (
LateFeeID Int Identity (1,1) NOT NULL,
LateFee Decimal(10,2) NULL,
LateFeeReceived datetime NULL
)

CREATE TABLE LateFeeLog (
LateFeeLogID Int Identity (1,1) NOT NULL,
LateFeeID Int NOT NULL,
LateFee Decimal(10,2) NULL,
LateFeeReceived datetime NULL
)

Then you would need to create a couple of triggers:

-- First trigger for inserts
CREATE TRIGGER trgLateFeeInsert
ON LateFee
FOR INSERT

AS

INSERT INTO LateFeeLog (LateFeeID, LateFee)
SELECT LateFeeID, LateFee FROM inserted

-- second trigger for updates
CREATE TRIGGER trgLateFeeUpdate
ON LateFee
FOR UPDATE

AS UPDATE dbo.LateFeeLog
SET LateFeeReceived = inserted.LateFeeReceived
FROM dbo.LateFeeLog inner join inserted ON
dbo.LateFeeLog.LateFeeID = inserted.LateFeeID|||Thanks. This is big help.

Sunday, February 19, 2012

Imporint CSV file using store procedure

I would like to create DTS for Importing from CSV using store procedure, in
which I would like to update fields conditionally.
Anyone can help in this matter or let me know url/tutorial on this.
Thanks in advance
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004Ashish,
there are various ways of doing this. My preference is to import the data to a staging
area in SQL Server then use Execute SQL tasks (TSQL) to clean/transform it, before impo
rting it to the production system. Alternatively you can do row by row iteration and fo
r each row decide what to do using VBScript. It sounds like this is the route you're in
terested in, and in that case the Transform data task with Lookup queries would be usef
ul. For more info, have a look at http://www.sqldts.com/default.aspx?277.
HTH,
Paul Ibison|||I made the logic in , but how do this logic in DTS. Here is my logic
*---
Dim reccount As Double
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
strPathtoTextFile = "C:\"
objConn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;In
itial Catalog=stocks;Data Source=webserver1")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=FixedLength"""
objRecordset.Open "SELECT * FROM accounts.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
strCSV = "update accounts set closed = 0 where accountid=" & objRecordset.Fi
elds.Item("AccountID")
objConn.Execute strCSV
objRecordset.MoveNext
Loop
objRecordset.Close
objRecordset.Open "select count(*) from accounts where closed=0", objConn
MsgBox objRecordset(0)
*--
"Ashish Kanoongo" <ashishk@.armour.com> wrote in message news:uvSKyXuSEHA.398
8@.tk2msftngp13.phx.gbl...
I would like to create DTS for Importing from CSV using store procedure, in
which I would like to update fields conditionally.
Anyone can help in this matter or let me know url/tutorial on this.
Thanks in advance
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004|||Ashish,
have a look at the Transform Data Task with lookups integrated (lookups can
also do updates, despite their name)
http://www.sqldts.com/default.aspx?277,1
HTH,
Paul Ibison

Imporint CSV file using store procedure

I would like to create DTS for Importing from CSV using store procedure, in which I would like to update fields conditionally.
Anyone can help in this matter or let me know url/tutorial on this.
Thanks in advance
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004
Ashish,
there are various ways of doing this. My preference is to import the data to a staging area in SQL Server then use Execute SQL tasks (TSQL) to clean/transform it, before importing it to the production system. Alternatively you can do row by row iteration and for each row decide what to do using VBScript. It sounds like this is the route you're interested in, and in that case the Transform data task with Lookup queries would be useful. For more info, have a look at http://www.sqldts.com/default.aspx?277.
HTH,
Paul Ibison
|||I made the logic in , but how do this logic in DTS. Here is my logic
*---
Dim reccount As Double
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
strPathtoTextFile = "C:\"
objConn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=stocks;Data Source=webserver1")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=FixedLength"""
objRecordset.Open "SELECT * FROM accounts.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
strCSV = "update accounts set closed = 0 where accountid=" & objRecordset.Fields.Item("AccountID")
objConn.Execute strCSV
objRecordset.MoveNext
Loop
objRecordset.Close
objRecordset.Open "select count(*) from accounts where closed=0", objConn
MsgBox objRecordset(0)
*--
"Ashish Kanoongo" <ashishk@.armour.com> wrote in message news:uvSKyXuSEHA.3988@.tk2msftngp13.phx.gbl...
I would like to create DTS for Importing from CSV using store procedure, in which I would like to update fields conditionally.
Anyone can help in this matter or let me know url/tutorial on this.
Thanks in advance
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004
|||Ashish,
have a look at the Transform Data Task with lookups integrated (lookups can
also do updates, despite their name)
http://www.sqldts.com/default.aspx?277,1
HTH,
Paul Ibison