Showing posts with label linked. Show all posts
Showing posts with label linked. Show all posts

Tuesday, March 20, 2012

Approach Help to load Data from Flatfiles into relational table where Data is coming as spaces i

Hi ,

My Input is a flat file source and it has spaces in few columns in the data . These columns are linked to another table as a foreign key and when i try loading them in a relational structure Foreigh key violation is occuring , is there a standard method to replace these spaces .

what approach should i take so that data gets loaded in a relational structure.

for example

Name Age Salary Address

dsds 23 fghghgh

Salary description level

2345 nnncncn 4

here salary is used in this example , the datatype is char in real scenario

what approach should i take to load the data in with cleansing the spaces in ssis

Assumption: You don't have any control over the structure of the destination tables, but you can add records.

To maintain your foreign key constraint, you will need to create a "salary" record that you can use where salary is not defined. EG:

Salary Description Level

9999 Not Assigned 1

Then you can use a Derived Column expression to create a new column in your dataset that uses an If expression and then write that derived column to your destination table

Like this:

Code Snippet

[Salary]=="" ? 9999 : [Salary]

This is not an optimal solution (even though it is very practical.) Ideally you should restructure your tables so:

Assumption: You can change the structure of your destination tables

In this case, you need to take the Salary column out of your destination table, and put it into another table. The relationship is that employees can have zero or one salary code. So you can create a table relating employees to salary codes with two columns (EmployeeNumber, SalaryCode) and a primary key on EmployeeCode.

(This is a drastic simplification, of course. In a real-world scenario you would probably want to track historical information too.)

|||

Thanks for the Quick reply i tried doing as you said using derived transformation and using replace function but it doesnot seem to capture the space as value in the replace expression in ssis.

Replace(salary," ",9999) it does not work it says that there might be a possibility of divide by zero error. what expression should i use here to replace the values

|||

first of all, since this is a char value, you should put quotes around the 9999.

Seond, I didn't say to use the REPLACE function, though I guess that would work, but you run the risk of having a valid id messed up by replacing a leading or trailing space with a 9999.

Also, if your Salary code was " " (eight spaces) then the REPLACE function will put in:

"99999999999999999999999999999999" which migh be too big for your destination field.

So, try using TRIM first to get ris of spaces, then ?: to replace blank with 9999.

Put this into the Expression column of Derived Value step:

Code Snippet

TRIM([SALARY])=="" ? "9999" : TRIM([Salary])

sql

Wednesday, March 7, 2012

Application role to access xp_cmdshell

I have an Access app linked to a SQL server db. This app uses
xp_cmdshell in some stored procedures and it works fine. As long as
the user is administrator... I'd like to set up an application role
that can execute xp_cmdshell and access my db but I don't know how to
do it as xp_cmdshell is in the Master db while everything else is in
my own db. I'm also unsure whether to call sp_setapprole from the sp's
or from the Access app.
Can somebody please give me some code examples or direct me to a good
site?
/CarlAs long as the ownership chain is unbroken, direct permissions on
xp_cmdshell are not needed. This necessitates that your user procs be owned
by 'dbo', your user database be owned by 'sa' and cross-database chaining
(intoduced in SQL 2000 SP3) be enabled. Example script below.
For security reasons, it is important that your user proc be coded in such a
way that only the intended command can be executed. Also, you should enable
cross-database chaining only if you fully trust users that have permissions
to create dbo-owned objects. See Cross-database chaining in the SQL 2000
Books Online for more information.
You will also need to allow non-sysadmin users to execute xp_cmdshell. You
can do this from Enterprise Manager under Management-->SQL Server
Agent-->Job System. Uncheck the 'Only users with sysadmin privileges...'
check box and specify the Windows account you want to use as the OS security
context for non-sysadmin users. This account should have the minimal
permissions need to perform the needed tasks.

> I'm also unsure whether to call sp_setapprole from the sp's
> or from the Access app.
You'll need to execute sp_setapprole directly from your application. From
the Books Online:
<Excerpt href="http://links.10026.com/?link=tsqlref.chm::/ts_sp_sa-sz_6tt1.htm">
The sp_setapprole stored procedure can be executed only by direct
Transact-SQL statements; it cannot be executed within another stored
procedure or from within a user-defined transaction.
</Excerpt>
USE MyDatabase
EXEC sp_changedbowner 'sa'
GO
-- for SQL 2000 SP3+
EXEC sp_dboption 'MyDatabase', 'db chaining', true
GO
CREATE PROC dbo.MyXpCmdShellProc
AS
EXEC master..xp_cmdshell 'MyCommand'
GO
GRANT EXEC ON dbo.MyXpCmdShellProc TO MyAppRole
GO
EXEC sp_setapprole 'MyAppRole', 'MyAppRolePassword'
EXEC dbo.MyXpCmdShellProc
GO
Hope this helps.
Dan Guzman
SQL Server MVP
"Carl Olsson" <caos@.regerar.com> wrote in message
news:d495b147.0402170439.d8b1453@.posting.google.com...
> I have an Access app linked to a SQL server db. This app uses
> xp_cmdshell in some stored procedures and it works fine. As long as
> the user is administrator... I'd like to set up an application role
> that can execute xp_cmdshell and access my db but I don't know how to
> do it as xp_cmdshell is in the Master db while everything else is in
> my own db. I'm also unsure whether to call sp_setapprole from the sp's
> or from the Access app.
> Can somebody please give me some code examples or direct me to a good
> site?
> /Carl|||Thanks Dan for your excellent explanation. But unfortunately I'm still
at SQL 7... Any other options?
Carl
"Dan Guzman" <danguzman@.nospam-earthlink.net> wrote in message news:<#kQj98V9DHA.3176@.TK
2MSFTNGP11.phx.gbl>...
> As long as the ownership chain is unbroken, direct permissions on
> xp_cmdshell are not needed. This necessitates that your user procs be own
ed
> by 'dbo', your user database be owned by 'sa' and cross-database chaining
> (intoduced in SQL 2000 SP3) be enabled. Example script below.
>|||The technique will work with SQL 7 too. The only difference is that
cross-database chaining is not configurable under SQL 7 and pre-SQL2000 SP3
(it is always on). Just remember to run the 'db chaining' option on in your
user database if you later upgrade to SQL 2000 SP3+.
Hope this helps.
Dan Guzman
SQL Server MVP
"Carl Olsson" <caos@.regerar.com> wrote in message
news:d495b147.0402172316.6a6cf8b@.posting.google.com...
> Thanks Dan for your excellent explanation. But unfortunately I'm still
> at SQL 7... Any other options?
> Carl
>
> "Dan Guzman" <danguzman@.nospam-earthlink.net> wrote in message
news:<#kQj98V9DHA.3176@.TK2MSFTNGP11.phx.gbl>...
owned
chaining

Thursday, February 16, 2012

Append query from Access Table to Linked SQL Server Table Failing

Strange one here - I am posting this in both SQL Server and Access forums

Access is telling me it can't append any of the records due to a key violation.

The query:

INSERT INTO dbo_Colors ( NameColorID, Application, Red, Green, Blue )
SELECT Colors_Access.NameColorID, Colors_Access.Application, Colors_Access.Red, Colors_Access.Green, Colors_Access.Blue
FROM Colors_Access;

Colors_Access is linked from another MDB and dbo_Colors is linked from SQL Server 2000.

There are no indexes or foreign contraints on the SQL table. I have no relationships on the dbo_ table in my MDB. The query works if I append to another Access table. The datatypes all match between the two tables though the dbo_ tables has two additional fields not refrenced in the query.

I can manually append the records using cut and paste with no problems.

I have tried re-linking the tables.

Any ideas?
Thanks,
BradI'd guess that the SQL Server db you think you are linking to in dbo_Colors isn't really the one you think. Perhaps the login/password in your datasource is connecting to a different database than the one you expect?

To check, get the name of the constraint being violated and check in the sql server table to see if that constraint exists

Also, try running the sql server profiler to see what sql server db ms access is trying to insert data into|||mattrevs,

It does appear that I am linking the right table. There is only one Colors table and only one database that has a colors table.

Could you tell me how to check which constraint is being violated? After I manually pasted the data into dbo_Colors, I ran checkconstraints() and no error were reported.

I also tried running the query with implicit_transaction OFF and still no joy.

I ran the trace and here are the last two lines. The first one was simply duplicated for each record:

RPC:Completed exec sp_executesql N'INSERT INTO "dbo"."Colors" ("NameColorID","Application","Red","Green","Blue") VALUES (@.P1,@.P2,@.P3,@.P4,@.P5)', N'@.P1 nvarchar(38),@.P2 nvarchar(30),@.P3 int,@.P4 int,@.P5 int', N'{FFC28EAD-1134-40BB-9723-7D88A0B0AC7A}', N'Tile1', 197, 183, 156 Microsoft Access sa 0 11 0 0 2564 54 2004-06-21 10:35:14.170

SQL:BatchCompleted IF @.@.TRANCOUNT > 0 ROLLBACK TRAN Microsoft Access sa 0 0 0 0 2564 54 2004-06-21 10:35:19.403

- Brad|||You say that pasting the data one row at a time from within ms access works ok?

If so, maybe you could also perform a sql trace on this and see what is different?|||I got it figured out. (BTW, I did the trace with the pasting but the results were ... confusing)

Apparently a bit field in SQL server can be Null?

There are two additional fields in the SQL version of the table. The NVarChar field I had set to allow nulls. I never bothered with the Bit field.

When I checked Allow Nulls on the bit field and re-linked, my query worked.

I guess my lesson her is never assume anything. I have learned that lesson many times and will probably learn it again in the (near) future.

Thanks for your help,
Brad

Append data to Sql Server 2000 table from DB2 table (linked server)

Hello,
I am trying to append new records from a DB2 database to a Sql Server
2000 database. Basically table A (Sql Server) has been uploaded with a
dump from table B (DB2) and from know on I would like to append any new
records added to table B to table A. I am running a DTS package to do
this every night. The columns are CV_NBR, NOTE_OWNER, NOTE_DATE,
NOTE_SEQ_NBR, NOTE_TEXT where CV_NBR, NOTE_DATE, NOTE_SEQ_NBR would be
primary keys.
Any ideas.
Thanks for your helpThe usual approach is to load the data into a staging table, which
matches the target table in layout but is truncated before the load.
Then you can INSERT to the target table from the staging table where
NOT EXISTS the key. You also have the option of doing an UPDATE to
the target table from the staging table, which would be done before
the INSERT.
Roy Harvey
Beacon Falls, CT
On 15 Jan 2007 10:57:21 -0800, mrdata1701@.gmail.com wrote:
>Hello,
>I am trying to append new records from a DB2 database to a Sql Server
>2000 database. Basically table A (Sql Server) has been uploaded with a
>dump from table B (DB2) and from know on I would like to append any new
>records added to table B to table A. I am running a DTS package to do
>this every night. The columns are CV_NBR, NOTE_OWNER, NOTE_DATE,
>NOTE_SEQ_NBR, NOTE_TEXT where CV_NBR, NOTE_DATE, NOTE_SEQ_NBR would be
>primary keys.
>Any ideas.
>Thanks for your help|||Thanks Roy! The thing is the table has over 380K records so it would
take a while to update and this is something that will be run daily so
it could end up using more resources that I would like.
On Jan 15, 2:16 pm, Roy Harvey <roy_har...@.snet.net> wrote:
> The usual approach is to load the data into a staging table, which
> matches the target table in layout but is truncated before the load.
> Then you can INSERT to the target table from the staging table where
> NOT EXISTS the key. You also have the option of doing an UPDATE to
> the target table from the staging table, which would be done before
> the INSERT.
> Roy Harvey
> Beacon Falls, CT
> On 15 Jan 2007 10:57:21 -0800, mrdata1...@.gmail.com wrote:
>
> >Hello,
> >I am trying to append new records from a DB2 database to a Sql Server
> >2000 database. Basically table A (Sql Server) has been uploaded with a
> >dump from table B (DB2) and from know on I would like to append any new
> >records added to table B to table A. I am running a DTS package to do
> >this every night. The columns are CV_NBR, NOTE_OWNER, NOTE_DATE,
> >NOTE_SEQ_NBR, NOTE_TEXT where CV_NBR, NOTE_DATE, NOTE_SEQ_NBR would be
> >primary keys.
> >Any ideas.
> >Thanks for your help- Hide quoted text -- Show quoted text -|||On 15 Jan 2007 11:26:59 -0800, mrdata1701@.gmail.com wrote:
>Thanks Roy! The thing is the table has over 380K records so it would
>take a while to update and this is something that will be run daily so
>it could end up using more resources that I would like.
The ideal would be to have the DB2 data marked in some indicating
which rows had been updated. Lacking that your alternatives are to
use a staging table as already described, or process today's DB2
extract against yesterday's DB2 extract in an old fashioned match-file
program written in whatever language you prefer. That assumes that
the files are already sorted on the key, of course. Personally I
would try the staging table approach first.
Roy Harvey
Beacon Falls, CT

Append data to Sql Server 2000 table from DB2 table (linked server)

Hello,
I am trying to append new records from a DB2 database to a Sql Server
2000 database. Basically table A (Sql Server) has been uploaded with a
dump from table B (DB2) and from know on I would like to append any new
records added to table B to table A. I am running a DTS package to do
this every night. The columns are CV_NBR, NOTE_OWNER, NOTE_DATE,
NOTE_SEQ_NBR, NOTE_TEXT where CV_NBR, NOTE_DATE, NOTE_SEQ_NBR would be
primary keys.
Any ideas.
Thanks for your help
The usual approach is to load the data into a staging table, which
matches the target table in layout but is truncated before the load.
Then you can INSERT to the target table from the staging table where
NOT EXISTS the key. You also have the option of doing an UPDATE to
the target table from the staging table, which would be done before
the INSERT.
Roy Harvey
Beacon Falls, CT
On 15 Jan 2007 10:57:21 -0800, mrdata1701@.gmail.com wrote:

>Hello,
>I am trying to append new records from a DB2 database to a Sql Server
>2000 database. Basically table A (Sql Server) has been uploaded with a
>dump from table B (DB2) and from know on I would like to append any new
>records added to table B to table A. I am running a DTS package to do
>this every night. The columns are CV_NBR, NOTE_OWNER, NOTE_DATE,
>NOTE_SEQ_NBR, NOTE_TEXT where CV_NBR, NOTE_DATE, NOTE_SEQ_NBR would be
>primary keys.
>Any ideas.
>Thanks for your help
|||Thanks Roy! The thing is the table has over 380K records so it would
take a while to update and this is something that will be run daily so
it could end up using more resources that I would like.
On Jan 15, 2:16 pm, Roy Harvey <roy_har...@.snet.net> wrote:[vbcol=seagreen]
> The usual approach is to load the data into a staging table, which
> matches the target table in layout but is truncated before the load.
> Then you can INSERT to the target table from the staging table where
> NOT EXISTS the key. You also have the option of doing an UPDATE to
> the target table from the staging table, which would be done before
> the INSERT.
> Roy Harvey
> Beacon Falls, CT
> On 15 Jan 2007 10:57:21 -0800, mrdata1...@.gmail.com wrote:
>
>
>
|||On 15 Jan 2007 11:26:59 -0800, mrdata1701@.gmail.com wrote:

>Thanks Roy! The thing is the table has over 380K records so it would
>take a while to update and this is something that will be run daily so
>it could end up using more resources that I would like.
The ideal would be to have the DB2 data marked in some indicating
which rows had been updated. Lacking that your alternatives are to
use a staging table as already described, or process today's DB2
extract against yesterday's DB2 extract in an old fashioned match-file
program written in whatever language you prefer. That assumes that
the files are already sorted on the key, of course. Personally I
would try the staging table approach first.
Roy Harvey
Beacon Falls, CT

Append data to Sql Server 2000 table from DB2 table (linked server)

Hello,
I am trying to append new records from a DB2 database to a Sql Server
2000 database. Basically table A (Sql Server) has been uploaded with a
dump from table B (DB2) and from know on I would like to append any new
records added to table B to table A. I am running a DTS package to do
this every night. The columns are CV_NBR, NOTE_OWNER, NOTE_DATE,
NOTE_SEQ_NBR, NOTE_TEXT where CV_NBR, NOTE_DATE, NOTE_SEQ_NBR would be
primary keys.
Any ideas.
Thanks for your helpThe usual approach is to load the data into a staging table, which
matches the target table in layout but is truncated before the load.
Then you can INSERT to the target table from the staging table where
NOT EXISTS the key. You also have the option of doing an UPDATE to
the target table from the staging table, which would be done before
the INSERT.
Roy Harvey
Beacon Falls, CT
On 15 Jan 2007 10:57:21 -0800, mrdata1701@.gmail.com wrote:

>Hello,
>I am trying to append new records from a DB2 database to a Sql Server
>2000 database. Basically table A (Sql Server) has been uploaded with a
>dump from table B (DB2) and from know on I would like to append any new
>records added to table B to table A. I am running a DTS package to do
>this every night. The columns are CV_NBR, NOTE_OWNER, NOTE_DATE,
>NOTE_SEQ_NBR, NOTE_TEXT where CV_NBR, NOTE_DATE, NOTE_SEQ_NBR would be
>primary keys.
>Any ideas.
>Thanks for your help|||Thanks Roy! The thing is the table has over 380K records so it would
take a while to update and this is something that will be run daily so
it could end up using more resources that I would like.
On Jan 15, 2:16 pm, Roy Harvey <roy_har...@.snet.net> wrote:[vbcol=seagreen]
> The usual approach is to load the data into a staging table, which
> matches the target table in layout but is truncated before the load.
> Then you can INSERT to the target table from the staging table where
> NOT EXISTS the key. You also have the option of doing an UPDATE to
> the target table from the staging table, which would be done before
> the INSERT.
> Roy Harvey
> Beacon Falls, CT
> On 15 Jan 2007 10:57:21 -0800, mrdata1...@.gmail.com wrote:
>
>
>
>
>|||On 15 Jan 2007 11:26:59 -0800, mrdata1701@.gmail.com wrote:

>Thanks Roy! The thing is the table has over 380K records so it would
>take a while to update and this is something that will be run daily so
>it could end up using more resources that I would like.
The ideal would be to have the DB2 data marked in some indicating
which rows had been updated. Lacking that your alternatives are to
use a staging table as already described, or process today's DB2
extract against yesterday's DB2 extract in an old fashioned match-file
program written in whatever language you prefer. That assumes that
the files are already sorted on the key, of course. Personally I
would try the staging table approach first.
Roy Harvey
Beacon Falls, CT

Sunday, February 12, 2012

Anyway to find informatoin on how a record is deleted?

Hi,
One record, linked by a key tid, is deleted from several tables in the
database. Is there anyway to find information on when and who deleted the
recrod from SQL server?
Thanks,
AlphaYou can use a log viewing tool, such as:
Apex SQL Log
http://www.apexsql.com/index.asp?PageId=apex_sql_log&TitleID=products
Lumigent Log Explorer
http://www.lumigent.com/products/le_sql.html
Log P.I.
http://www.logpi.com/
--
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Alpha" <Alpha@.discussions.microsoft.com> wrote in message
news:B6572BE4-B0FE-4034-976F-EA21D1C5CC8F@.microsoft.com...
> Hi,
> One record, linked by a key tid, is deleted from several tables in the
> database. Is there anyway to find information on when and who deleted the
> recrod from SQL server?
> Thanks,
> Alpha

Anyway to find informatoin on how a record is deleted?

Hi,
One record, linked by a key tid, is deleted from several tables in the
database. Is there anyway to find information on when and who deleted the
recrod from SQL server?
Thanks,
Alpha
You can use a log viewing tool, such as:
Apex SQL Log
http://www.apexsql.com/index.asp?Pag...tleID=products
Lumigent Log Explorer
http://www.lumigent.com/products/le_sql.html
Log P.I.
http://www.logpi.com/
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Alpha" <Alpha@.discussions.microsoft.com> wrote in message
news:B6572BE4-B0FE-4034-976F-EA21D1C5CC8F@.microsoft.com...
> Hi,
> One record, linked by a key tid, is deleted from several tables in the
> database. Is there anyway to find information on when and who deleted the
> recrod from SQL server?
> Thanks,
> Alpha

Anyway to find informatoin on how a record is deleted?

Hi,
One record, linked by a key tid, is deleted from several tables in the
database. Is there anyway to find information on when and who deleted the
recrod from SQL server?
Thanks,
AlphaYou can use a log viewing tool, such as:
Apex SQL Log
http://www.apexsql.com/index.asp?Pa...itleID=products
Lumigent Log Explorer
http://www.lumigent.com/products/le_sql.html
Log P.I.
http://www.logpi.com/
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Alpha" <Alpha@.discussions.microsoft.com> wrote in message
news:B6572BE4-B0FE-4034-976F-EA21D1C5CC8F@.microsoft.com...
> Hi,
> One record, linked by a key tid, is deleted from several tables in the
> database. Is there anyway to find information on when and who deleted the
> recrod from SQL server?
> Thanks,
> Alpha