Showing posts with label loading. Show all posts
Showing posts with label loading. Show all posts

Thursday, March 29, 2012

Alternate to cursors

Hi,
I have a situation where I am loading data into a staging
table for multiple data sources. My next step is to pick up the
records from the staging table and compare with the data in the
database and based on the certain conditions, decide whether to insert
the data into the database or update an existing record in the
database. I have to do this job as an sp and schedule it to run on the
server as per the requirements. I thought that cursors are the only
option in this situation. Can anyone suggest if there is any other way
to achieve this in SQL 2005 please.

Thanks

SeshadriIn general this is done with two commands, an UPDATE of existing rows
followed by an INSERT of new rows. Very generally:

UPDATE Target
SET cola = A.cola,
colb - A.colb
FROM Staging as A
WHERE Target.keycol = Staging.keycol

INSERT Target
SELECT keycol, cola, colb
FROM Staging as A
WHERE NOT EXISTS
(SELECT * FROM Target as B
WHERE A.keycol = B.keycol)

Whether this fits your requirements is unknown because you didn't
provide much information. It would require knowing at least the table
definitions and keys, as well as the "certain conditions".

Roy Harvey
Beacon Falls, CT

On Mon, 01 Oct 2007 00:12:22 -0700, srirangam.seshadri@.gmail.com
wrote:

Quote:

Originally Posted by

>Hi,
I have a situation where I am loading data into a staging
>table for multiple data sources. My next step is to pick up the
>records from the staging table and compare with the data in the
>database and based on the certain conditions, decide whether to insert
>the data into the database or update an existing record in the
>database. I have to do this job as an sp and schedule it to run on the
>server as per the requirements. I thought that cursors are the only
>option in this situation. Can anyone suggest if there is any other way
>to achieve this in SQL 2005 please.
>
>Thanks
>
>Seshadri

Sunday, February 19, 2012

allowing null values

I have a flat file that I'm reading from and loading my tables with. In that file I have a column that has numbers (2000,1999,1998 and so on) and the column that they are being loaded into is defined as an INT. The issue I'm running into is that the first 50 or so rows in the flat file is empty for this column so I'm getting an error message. If I put numbers in that column in the flat file it works, if i remove them it fails. How can I allow for NULL values for my INT column on the database table?

here is the error I'm getting:

[OLE DB Destination [182]] Error: There was an error with input column "SalesYear" (7259) on input "OLE DB Destination Input" (195). The column status returned was: "The value could not be converted because of a potential loss of data.".What is the format of the flat file?

CSV? Tab delimited? Fixed width?|||

I got it to work, I had to go into the flat file connection and make some changes there on the field. Once I did that it loads correctly.

|||

IGotyourdotnet wrote:

I got it to work, I had to go into the flat file connection and make some changes there on the field. Once I did that it loads correctly.

Can you share what kind of changes you made to perhaps help others down the road?

Thanks.|||

I just changed the data type of the column. So instead of creating a derived column for it, I just changed it in the flat file connection manager.

|||I have a similar problem.Could you tell me what datatype you used in Flat file connection manager and the data type used in databse?|||

remsid wrote:

I have a similar problem.Could you tell me what datatype you used in Flat file connection manager and the data type used in databse?

Try a character data type.

allowing null values

I have a flat file that I'm reading from and loading my tables with. In that file I have a column that has numbers (2000,1999,1998 and so on) and the column that they are being loaded into is defined as an INT. The issue I'm running into is that the first 50 or so rows in the flat file is empty for this column so I'm getting an error message. If I put numbers in that column in the flat file it works, if i remove them it fails. How can I allow for NULL values for my INT column on the database table?

here is the error I'm getting:

[OLE DB Destination [182]] Error: There was an error with input column "SalesYear" (7259) on input "OLE DB Destination Input" (195). The column status returned was: "The value could not be converted because of a potential loss of data.".What is the format of the flat file?

CSV? Tab delimited? Fixed width?|||

I got it to work, I had to go into the flat file connection and make some changes there on the field. Once I did that it loads correctly.

|||

IGotyourdotnet wrote:

I got it to work, I had to go into the flat file connection and make some changes there on the field. Once I did that it loads correctly.

Can you share what kind of changes you made to perhaps help others down the road?

Thanks.|||

I just changed the data type of the column. So instead of creating a derived column for it, I just changed it in the flat file connection manager.

|||

I have a similar problem.Could you tell me what datatype you used in Flat file connection manager and the data type used in databse?|||

remsid wrote:

I have a similar problem.Could you tell me what datatype you used in Flat file connection manager and the data type used in databse?

Try a character data type.

Allow zero length

We ran into a problem loading access where tables where if we did not
select the property allow zero length we got an error message when
loading data with some empty values.

We are now ramping up SQL server and the question came up will SQL
server have the same problem with empty data values.

Is there an SQL server equivalent to allow zero length?SQL-Server will always allow zero length values, unless you explicitely
add a constraint to disallow this.

So, by default, zero length values are allowed. If you do not want that,
you could run

ALTER TABLE mytable
ADD CONSTRAINT constraintname
CHECK (mycol <> '')

for each relevant column.

Hope this helps,
Gert-Jan

William Kossack wrote:
> We ran into a problem loading access where tables where if we did not
> select the property allow zero length we got an error message when
> loading data with some empty values.
> We are now ramping up SQL server and the question came up will SQL
> server have the same problem with empty data values.
> Is there an SQL server equivalent to allow zero length?

--
(Please reply only to the newsgroup)|||thanks

Gert-Jan Strik wrote:

> SQL-Server will always allow zero length values, unless you explicitely
> add a constraint to disallow this.
> So, by default, zero length values are allowed. If you do not want that,
> you could run
> ALTER TABLE mytable
> ADD CONSTRAINT constraintname
> CHECK (mycol <> '')
> for each relevant column.
> Hope this helps,
> Gert-Jan
> William Kossack wrote:
> > We ran into a problem loading access where tables where if we did not
> > select the property allow zero length we got an error message when
> > loading data with some empty values.
> > We are now ramping up SQL server and the question came up will SQL
> > server have the same problem with empty data values.
> > Is there an SQL server equivalent to allow zero length?
> --
> (Please reply only to the newsgroup)