Showing posts with label types. Show all posts
Showing posts with label types. Show all posts

Wednesday, March 7, 2012

How do I extract data from selected rows from my excel source file?

The columns in my excel source contain data of different types with the column name being a string and the data in those columns being integers. Is there any way to only extract numeric data , in short I want column names to be omitted. Also the data is distributed unevenly , beggining at various rows in each column.

Thanking in advance :)

You can try to create a named range in the Excel sheet and then import only the range.

HTH.

|||Is there any other way to do it , like writing a query or so? I need help as i'm new to SSIS , any help would be appreciated

Sunday, February 19, 2012

How do I display a count?

I want to display the number of records for each state in a database. I'm using a strongly types dataset. In my method, I have the following

SELECT COUNT(ID) AS iTotal, STATE
FROM members
WHERE (Suspend = 0)
GROUP BY STATE
ORDER BY STATE

In the code behind of my page I have

Dim mateAdapter As New WAPTableAdapters.membersTableAdapter
Dim mates As WAP.membersDataTable
Dim mate As WAP.membersRow

mates = mateAdapter.GetDataState

For Each mate In mates
Select Case mate.STATE
Case "AK"
LabelAK.Text = mate.ID.
End Select
Next

What shouldLabelAK.Text = mate.ID. be for me to be able to display the number of records that have 'AK' in the state field?

Diane

I think if you use

LabelAK.Text = mate.iTotal

you'll get what you're looking for.

|||

That's what i thought, but it doesn't like it.

Description:Anerror occurred during the compilation of a resource required to servicethis request. Please review the following specific error details andmodify your source code appropriately.

Compiler Error Message:BC30456: 'iTotal' is not a member of 'WAP.membersRow'.

But it is in the dataset, and i can get a preview of the data in the dataset. But it doesn't like it in the page.

Diane

|||
Try mate.iTotal.ToString

I had some state and zipcode data around so I put this together.

webform:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:Label id="LabelMO" runat="server" Text="Label"></asp:Label> </div> </form></body></html>

code behind:

Imports WAPTableAdaptersPartialClass TestInherits System.Web.UI.PageProtected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs) _Handles Me.LoadDim mateAdapterAs New ZipcodesTableAdapterDim matesAs WAP.ZipcodesDataTableDim mateAs WAP.ZipcodesRow mates = mateAdapter.GetDataStateFor Each mateIn matesSelect Case mate.StateCase"MO" LabelMO.Text = mate.iTotal.ToStringEnd Select Next End SubEnd Class


GetDataStat method:

selectcount(Zipcode)as iTotal, Statefrom ZipcodesGroup by StateOrder by State
|||

I have exactly what you do, and I'm getting the error that iTotal is not a member of the row. There must be something I'm overlooking that I've got wrong. But when i compare mine with yours, I don't see a difference.

Diane

|||

That is very odd, I know how you feel though. Sometimes what seems like it should be so easy is infuriatingly difficult.

Post your code so I can play around with it, or you can send it to me at eterry28 @. gmail . com

|||

Thank youeterry28

I did post my code in the first post.

Diane

|||

I resolved my problem by returning the state field in all rows and changing my code to Inmates.Compute("count(STATE)", "STATE='VT'").ToString

Thanks for your help

Diane

how do I determine how many columns there are in a file?

Hi,

I have a few different files in a directory.

I want to take each file and determine which columns and data types it has.

How can I know how many columns there are in a file?

Thank you.

Columns. That depends entirely on what you define a column to be. How is it delimited?

Column data-type. In a file the type of every column is text/char/call it whatever you want. A file is just a text string. You give semantic meaning to those strings (e.g. data-types) which you define yourself.

There are a million and one answers to your question given the information that you have provided. Only you can answer it.

-Jamie

|||

Jamie,

let's assume that I get a csv file from my customer.

I don't know how many columns there are in that file (and I don't want to count it by myself).

I wanted to know which component can take this file and tell me how many columns it has.

This is stage 1.

|||

The Flat File allows you to define a delimiter and therefore tell you how many columns there are.

-Jamie

|||

suppose I use a "flat file" component, and I see that there are 4 columns.

I want to use the "for each" component and apply a "data flow task" on each one of the columns.

The "for each" component will take one column at a time, and run 4 times.

I want to use the same "data flow task" for all of the columns.

How can I do it automatically?

|||

one way is to start a new project in vs as ssis

right click over solution explorer->SSIS Packages and select import and export wizard

select your flat file as source and destination as server, by this way create a new package for every text file, later you can copy and paste of each package contents into one and with little change this will be work for you and hope you get column list by looking at tables.

|||

reut wrote:

suppose I use a "flat file" component, and I see that there are 4 columns.

I want to use the "for each" component and apply a "data flow task" on each one of the columns.

The "for each" component will take one column at a time, and run 4 times.

I want to use the same "data flow task" for all of the columns.

How can I do it automatically?

Data flows operate on datasets, not on a column at a time. Even if you could do what you want to (which you can't - see below) I would recommend not doing it.

The reason that you can't apply the same data-flow to different data set (which in your case would exist of a single column) is because the metadata of the the data-flow (i.e. the columns) is set at design-time and cannot be changed when the package is executed.

-Jamie

|||

This is a good way, thanks for that, but what do I do if I have 30 different files with 100 columns in each one of them, and I don"t want to create 30 different packages?...

I want to create one "smart" packege, that will take a file, take a column, and insert the relevant data into a table on the server.

If I decide to do it with the "for each" component, it will run 30*100 times.

The resault has to be something like this:

fileName columnName dataType

xxx.csv column1 int

xxx.csv column2 date

...

xxx.csv column100 varchar

yyy.csv column1 date

...

How do I do it?

Thank you for your patience.

|||

you can create a raw table with columns from 1 to 500, then fetch every text file into it and call that data flow in your for each loop and then you better know which column tells you about specific table then put the data into that table from raw table by calling just one stored proc from your ssis, and that sp will decide data insert into that specific table based on data

|||

Your only option is to create a "Smart" custom source that is either a script source or a script component. Your custom component would take the column name, or position and output the relevant column into the data flow.

You could also unpivot the data so that your columns were now rows. You then filter the flow based on the column you want to process.