Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Monday, March 26, 2012

Looping through several Excel data sources in SSIS

I am attempting to use the foreach loop structure in an SSIS package to
loop through however many Excel files are placed in a directory and
then perform an import operation into a SQL table on each of these
files sequentially. The closest model for this that I was able to find
in the MS tutorial used a flat file source rather than Excel. That
involved adding a new expression to the Connection Manager that set the
connection string to the current filename, as provided by the foreach
component. That works just fine, but when I attempt to apply the same
method to an Excel source, rather than a flat file source, I cannot get
it to work. I see the following error associated with the Excel source
on the Data Flow page: "Validation error. Data Flow Task: Excel Source
[1]: The AcquireConnection method call to the connection manager "Excel
Connection Manager 1" failed with error code 0xC020200." I think that
it's just a matter of getting the right expression, and I thought that
perhaps I should be constructing an expression for ExcelFilePath rather
than the Connection String, but I have fiddled with it for hours and
haven't come up with something that will be accepted. Has anybody out
there been able to do this, or can perhaps refer me to some
documentation that contains an example of what I am trying to do?
Thanks for any help you can give.David,

The April 2006 update of SQL Server 2005 Books Online contains a
new topic titled "How to: Loop through Excel Files and Tables", at
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/extran9/html/a5393c1a-cc37-491a-a260-7aad84dbff68.htm
or online at
http://msdn2.microsoft.com/en-us/library/ms345182.aspx

Why don't you see if that helps, and if not, let us know exactly
what point in that article something goes wrong.

The download page for BOL, for local installation, is
http://www.microsoft.com/downloads/...&DisplayLang=en

Steve Kass
Drew University

davidz wrote:
> I am attempting to use the foreach loop structure in an SSIS package to
> loop through however many Excel files are placed in a directory and
> then perform an import operation into a SQL table on each of these
> files sequentially. The closest model for this that I was able to find
> in the MS tutorial used a flat file source rather than Excel. That
> involved adding a new expression to the Connection Manager that set the
> connection string to the current filename, as provided by the foreach
> component. That works just fine, but when I attempt to apply the same
> method to an Excel source, rather than a flat file source, I cannot get
> it to work. I see the following error associated with the Excel source
> on the Data Flow page: "Validation error. Data Flow Task: Excel Source
> [1]: The AcquireConnection method call to the connection manager "Excel
> Connection Manager 1" failed with error code 0xC020200." I think that
> it's just a matter of getting the right expression, and I thought that
> perhaps I should be constructing an expression for ExcelFilePath rather
> than the Connection String, but I have fiddled with it for hours and
> haven't come up with something that will be accepted. Has anybody out
> there been able to do this, or can perhaps refer me to some
> documentation that contains an example of what I am trying to do?
> Thanks for any help you can give.

Wednesday, March 21, 2012

loop through informationSchema.Columns table

Well, I came up with one loop structure that isn't dying,
but my table is not getting updated. Here is what I
tried - any suggestions appreciated if anyone spots what
is wrong: can I say this?
Declare @.fldName varchar(20)
Select @.fldName = 'fld1'
Update tbl1 Set @.fldName = 'test'
--here is my effort
DECLARE @.iNextRowId int,
@.iCurrentRowId int,
@.iLoopControl int,
@.fldName nvarchar(255)
-- Initialize variables!
SELECT @.iLoopControl = 1
SELECT @.iNextRowId = MIN(ordinal_position)
FROM information_schema.columns
where table_name = 'tbl1'
-- Make sure the table has data.
IF ISNULL(@.iNextRowId,0) = 0
BEGIN
SELECT 'No data in found in table!'
END
-- Retrieve the first row
SELECT @.iCurrentRowId = ordinal_position,
@.fldName = column_Name
FROM information_schema.columns
where table_name = 'tbl1' AND Ordinal_Position =
@.iNextRowId
print @.fldName --OK to here
-- start the main processing loop.
WHILE @.iLoopControl = 1
BEGIN
-- perform detailed row-by-row processing.
Update tbl1 Set @.fldName = ltrim(rtrim(@.fldName))
-- Reset looping variables.
SELECT @.iNextRowId = NULL
-- get the next iRowId
SELECT @.iNextRowId = MIN(Ordinal_Position)
From information_schema.columns
where table_name = 'tbl1' AND Ordinal_Position >
@.iCurrentRowId
-- did we get a valid next row id?
IF ISNULL(@.iNextRowId,0) = 0
BEGIN
BREAK
END
-- get the next row.
SELECT @.iCurrentRowId = Ordinal_Position,
@.fldName = Column_Name
From information_schema.columns
where table_name = 'tbl1' AND Ordinal_Position >
@.iNextRowId
END

>--Original Message--
>Hello,
>I have to import a dataset from a mainframe to Sql Server
>which contains about 100 fields, and about 90 of the
>fields have leading and trailing spaces in the data.
>After I import the data to a table in Sql Server I need
to
>update this table to remove the leading/trailing spaces.
>But rather that writing a query like
>Update tbl1 Set fld1 = ltrim(rtrim(fld1)), fld2 = ...
>I was hoping to loop through the
>Information_Schema.Columns table and use a loop to loop
>through all the fields in tbl1 to update each field. Is
>this a good approach? If so, what kind of loop do I want
>to use? How to set that up?
>Thanks,
>Ron
>.
>--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
You can't use a variable for a column/table name. This:
Update tbl1 Set @.fldName = ltrim(rtrim(@.fldName))
won't work. 1) because the SET clause needs a column name, not a
variable. 2) because the LTrim(RTrim(@.fldName)) will trim the actual
column name, not the value of the column.
You should use a DTS package to Transform (the T in DTS) the data to an
acceptable format while importing it. Read the Books on Line (BOL)
articles on the Data Transformation Services (DTS) for more info.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/ AwUBQkjsCYechKqOuFEgEQKC6ACgtgkTdhZXm3bp
pTmsBUjBhP3xFKsAoLUU
hvG1jAtvQgKL3ulV49gzZQCG
=IF7t
--END PGP SIGNATURE--
Ron wrote:
> Well, I came up with one loop structure that isn't dying,
> but my table is not getting updated. Here is what I
> tried - any suggestions appreciated if anyone spots what
> is wrong: can I say this?
> Declare @.fldName varchar(20)
> Select @.fldName = 'fld1'
> Update tbl1 Set @.fldName = 'test'
> --here is my effort
> DECLARE @.iNextRowId int,
> @.iCurrentRowId int,
> @.iLoopControl int,
> @.fldName nvarchar(255)
> -- Initialize variables!
> SELECT @.iLoopControl = 1
> SELECT @.iNextRowId = MIN(ordinal_position)
> FROM information_schema.columns
> where table_name = 'tbl1'
> -- Make sure the table has data.
> IF ISNULL(@.iNextRowId,0) = 0
> BEGIN
> SELECT 'No data in found in table!'
> END
> -- Retrieve the first row
> SELECT @.iCurrentRowId = ordinal_position,
> @.fldName = column_Name
> FROM information_schema.columns
> where table_name = 'tbl1' AND Ordinal_Position =
> @.iNextRowId
> print @.fldName --OK to here
> -- start the main processing loop.
> WHILE @.iLoopControl = 1
> BEGIN
> -- perform detailed row-by-row processing.
> Update tbl1 Set @.fldName = ltrim(rtrim(@.fldName))
> -- Reset looping variables.
> SELECT @.iNextRowId = NULL
> -- get the next iRowId
> SELECT @.iNextRowId = MIN(Ordinal_Position)
> From information_schema.columns
> where table_name = 'tbl1' AND Ordinal_Position >
> @.iCurrentRowId
> -- did we get a valid next row id?
> IF ISNULL(@.iNextRowId,0) = 0
> BEGIN
> BREAK
> END
> -- get the next row.
> SELECT @.iCurrentRowId = Ordinal_Position,
> @.fldName = Column_Name
> From information_schema.columns
> where table_name = 'tbl1' AND Ordinal_Position >
> @.iNextRowId
> END
>
>
> to
>

Monday, March 12, 2012

Lookup table structure

I have another lookup table question

so say i have an employee table, and a department table. all the department table will do is store the names of the different departments so how should this be set up using MSSQL

Employee
EmployeeId
FN
LN
DeptName (fk)

Department
DeptId (pk) unique
DeptName unique

*** Or could i do this to make the employee record more meaningful without needing a join. ***

Employee
EmployeeId
FN
LN
DeptName (fk)

Department
DeptId (pk) unique
DeptName unique

*** Or should i just do this and get rid of the Id Field***
Employee
EmployeeId
FN
LN
DeptName (fk)

Department
DeptName (pk) unique

thanks all

I would use DeptID as the FK in Employees -NOT DeptName.

|||+1 I can second that.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

Wednesday, March 7, 2012

Looking for SQL-Server documenter

Hi everybody,
I'm looking for a documenter for the SQL-Server. It should describe the
tables, views with its structure (fieldnames, type, length, etc.) and
equally important it should be possible to export this information in a file
(XML, CSV, whatever).
Does anybody knows a tool like that and if so, where to get it?
Thx in advance
MichaelTry SQl Scribe Docuemtnation Builder
http://www.ag-software.com
--
kind regards
Greg O
Need to document your databases. Use the first and still the best AGS SQL
Scribe
http://www.ag-software.com
"Michael Bender" <technik@.salescom.de> wrote in message
news:df69m7$kjp$03$1@.news.t-online.com...
> Hi everybody,
> I'm looking for a documenter for the SQL-Server. It should describe the
> tables, views with its structure (fieldnames, type, length, etc.) and
> equally important it should be possible to export this information in a
> file
> (XML, CSV, whatever).
> Does anybody knows a tool like that and if so, where to get it?
> Thx in advance
> Michael
>|||Michael Bender wrote:
> Hi everybody,
> I'm looking for a documenter for the SQL-Server. It should describe the
> tables, views with its structure (fieldnames, type, length, etc.) and
> equally important it should be possible to export this information in a file
> (XML, CSV, whatever).
> Does anybody knows a tool like that and if so, where to get it?
> Thx in advance
> Michael
SchemaToDoc (http://www.schematodoc.com) will produce a Word document
that includes information about the tables and fields in your database.
The program documents: Primary Keys, Field Information (type, size,
defaults, nullable), Indexes, Check Constraints, Descriptions/Comments,
Foreign Keys, and Triggers. The program also lets you annotate your
tables and fields, and include those comments in the Word doc.

Looking for SQL-Server documenter

Hi everybody,
I'm looking for a documenter for the SQL-Server. It should describe the
tables, views with its structure (fieldnames, type, length, etc.) and
equally important it should be possible to export this information in a file
(XML, CSV, whatever).
Does anybody knows a tool like that and if so, where to get it?
Thx in advance
Michael
Try SQl Scribe Docuemtnation Builder
http://www.ag-software.com
kind regards
Greg O
Need to document your databases. Use the first and still the best AGS SQL
Scribe
http://www.ag-software.com
"Michael Bender" <technik@.salescom.de> wrote in message
news:df69m7$kjp$03$1@.news.t-online.com...
> Hi everybody,
> I'm looking for a documenter for the SQL-Server. It should describe the
> tables, views with its structure (fieldnames, type, length, etc.) and
> equally important it should be possible to export this information in a
> file
> (XML, CSV, whatever).
> Does anybody knows a tool like that and if so, where to get it?
> Thx in advance
> Michael
>
|||Michael Bender wrote:
> Hi everybody,
> I'm looking for a documenter for the SQL-Server. It should describe the
> tables, views with its structure (fieldnames, type, length, etc.) and
> equally important it should be possible to export this information in a file
> (XML, CSV, whatever).
> Does anybody knows a tool like that and if so, where to get it?
> Thx in advance
> Michael
SchemaToDoc (http://www.schematodoc.com) will produce a Word document
that includes information about the tables and fields in your database.
The program documents: Primary Keys, Field Information (type, size,
defaults, nullable), Indexes, Check Constraints, Descriptions/Comments,
Foreign Keys, and Triggers. The program also lets you annotate your
tables and fields, and include those comments in the Word doc.

Looking for SQL-Server documenter

Hi everybody,
I'm looking for a documenter for the SQL-Server. It should describe the
tables, views with its structure (fieldnames, type, length, etc.) and
equally important it should be possible to export this information in a file
(XML, CSV, whatever).
Does anybody knows a tool like that and if so, where to get it?
Thx in advance
MichaelTry SQl Scribe Docuemtnation Builder
http://www.ag-software.com
--
kind regards
Greg O
Need to document your databases. Use the first and still the best AGS SQL
Scribe
http://www.ag-software.com
"Michael Bender" <technik@.salescom.de> wrote in message
news:df69m7$kjp$03$1@.news.t-online.com...
> Hi everybody,
> I'm looking for a documenter for the SQL-Server. It should describe the
> tables, views with its structure (fieldnames, type, length, etc.) and
> equally important it should be possible to export this information in a
> file
> (XML, CSV, whatever).
> Does anybody knows a tool like that and if so, where to get it?
> Thx in advance
> Michael
>|||Michael Bender wrote:
> Hi everybody,
> I'm looking for a documenter for the SQL-Server. It should describe the
> tables, views with its structure (fieldnames, type, length, etc.) and
> equally important it should be possible to export this information in a fi
le
> (XML, CSV, whatever).
> Does anybody knows a tool like that and if so, where to get it?
> Thx in advance
> Michael
SchemaToDoc (http://www.schematodoc.com) will produce a Word document
that includes information about the tables and fields in your database.
The program documents: Primary Keys, Field Information (type, size,
defaults, nullable), Indexes, Check Constraints, Descriptions/Comments,
Foreign Keys, and Triggers. The program also lets you annotate your
tables and fields, and include those comments in the Word doc.

Saturday, February 25, 2012

Looking for method to create stem and leaf graph

All,

I would appreciate any advice anyone might have to offer on how to approach creating a stem-and-leaf graph using t-sql. My table structure is as follows:

CREATE TABLE [dbo].[Responses](
[appraisalId] [char](9) NOT NULL,
[userId] [char](9) NOT NULL,
[res1] [decimal](5, 2) NOT NULL,
[res2] [decimal](5, 2) NOT NULL,
[res3] [decimal](5, 3) NOT NULL,
[res4] [decimal](5, 2) NOT NULL,
[res5] [decimal](5, 2) NOT NULL,
CONSTRAINT [PK_Responses] PRIMARY KEY CLUSTERED
(
[appraisalId] ASC,
[userId] ASC
))

ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res1] CHECK (([res1]>=(1) AND [res1]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res2] CHECK (([res2]>=(1) AND [res2]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res3] CHECK (([res3]>=(1) AND [res3]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res4] CHECK (([res4]>=(1) AND [res4]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res5] CHECK (([res5]>=(1) AND [res5]<=(5)))

The problem to be solved is to create a stem and leaf graph that shows for each response value column res1 to res5, with valid values 1.0 - 5.0, create a graph similar to the following:

5|11233445567789
4|12233445566789
3|11334556667789
2|11223444567889
1|12233345556778

It was my hope that I could do this using reporting services, but I'll almost settle for being able to produce a two column result set similar to the above.

Best,
Steven

Please post some sample data (input) & expected sample output data.

It will help us to understand the problem quickly.. Smile

|||I believe at this point I've come up with a solution that will work. Perhaps the task of just writing down here what little bit I did helped me to think more clearly about the problem to solve.

I was playing around with a stacked bar chart, and experimented with a custom fill, and wound up with something that actually looks quite like what I wanted.

Thanks for the assist!

Best,
B.

Looking for method to create stem and leaf graph

All,

I would appreciate any advice anyone might have to offer on how to approach creating a stem-and-leaf graph using t-sql. My table structure is as follows:

CREATE TABLE [dbo].[Responses](
[appraisalId] [char](9) NOT NULL,
[userId] [char](9) NOT NULL,
[res1] [decimal](5, 2) NOT NULL,
[res2] [decimal](5, 2) NOT NULL,
[res3] [decimal](5, 3) NOT NULL,
[res4] [decimal](5, 2) NOT NULL,
[res5] [decimal](5, 2) NOT NULL,
CONSTRAINT [PK_Responses] PRIMARY KEY CLUSTERED
(
[appraisalId] ASC,
[userId] ASC
))

ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res1] CHECK (([res1]>=(1) AND [res1]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res2] CHECK (([res2]>=(1) AND [res2]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res3] CHECK (([res3]>=(1) AND [res3]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res4] CHECK (([res4]>=(1) AND [res4]<=(5)))
ALTER TABLE [dbo].[Responses] WITH CHECK ADD CONSTRAINT [CK_Responses_res5] CHECK (([res5]>=(1) AND [res5]<=(5)))

The problem to be solved is to create a stem and leaf graph that shows for each response value column res1 to res5, with valid values 1.0 - 5.0, create a graph similar to the following:

5|11233445567789
4|12233445566789
3|11334556667789
2|11223444567889
1|12233345556778

It was my hope that I could do this using reporting services, but I'll almost settle for being able to produce a two column result set similar to the above.

Best,
Steven

Please post some sample data (input) & expected sample output data.

It will help us to understand the problem quickly.. Smile

|||I believe at this point I've come up with a solution that will work. Perhaps the task of just writing down here what little bit I did helped me to think more clearly about the problem to solve.

I was playing around with a stacked bar chart, and experimented with a custom fill, and wound up with something that actually looks quite like what I wanted.

Thanks for the assist!

Best,
B.