Fixed Column Output- Looping

Mar 20, 2008

I have table like below

ID AMT
1001 1234.560
1001 34.560
1001 134.000
1002 45.000
1002 3456.000
1003 5678.999


I need to create a fixed length data file..For example, ID char(6) and amt num(10.3) and sum(23.3)

It should be group and order by ID : 01 Represent ID line and 02 represent amt ( there can be multiple amt records) and 03 represent sum of amt.
01 + ID
02 + AMT
03 + Sum(AMT)


The output should look like this.. How do this either using a t-sql or SSIS?

011001
021234.560
0234.560
02134.00
031403.12
011002
0245.000
023456.000
033501.000
011003
025678.999
035678.999

View 6 Replies


ADVERTISEMENT

Looping With File Output

Oct 22, 2014

I'm converting a terribly written ColdFusion script and migrating it to T-SQL (SQL Server 2012). My problem is, I'm having issues with how to get these loops sorted out. For instaces, the CF query wouold be something like :

<cfquery name = "getData" datasource = "db">
SELECT id, name, date FROM table
</cfquery>

Following that, this query is looped into another set of queries:

<cfloop query = "getData">
<cfquery name = "getAddress" datasource = "globaladdress">
select * from globalAddress
where addressID = '#addressID#'
</cfquery>

[code]...

What I'm looking to do is turn the first query "getData" into the above loop, but rather in T-SQL.

View 4 Replies View Related

Generate Fixed Output

Mar 21, 2008

I have table like below

ID AMT
1001 1234.560
1001 34.560
1001 134.000
1002 45.000
1002 3456.000
1003 5678.999


I need to create a fixed length data file..For example, ID char(6) and amt num(10.3) and sum(23.3)

It should be group and order by ID : 01 Represent ID line and 02 represent amt ( there can be multiple amt records) and 03 represent sum of amt.
01 + ID
02 + AMT
03 + Sum(AMT)


The output should look like this.. How do this either using a sql or cursor?

011001
021234.560
0234.560
02134.00
031403.12
011002
0245.000
023456.000
033501.000
011003
025678.999
035678.999

View 4 Replies View Related

Fixed Length File Output

Feb 5, 2008

I need to write data into a fixed column length file and was wondering the best (most efficient) way to tackle this. For example, the first few pieces of the report I'm working on now would be:

PacketID - Starting position 1, Field length 9
TransactionID - Starting position 10, Field length 9
Group number - Starting position 19, field length 10
PID/SSN - Starting position 29, field length 10

For the PID/SSN, if I have a PID it'll be 10 digits and fill the field length, if I don't I use SSN which is only 9 digits and enter a space as the 10th digit. Obviously if I don't have certain pieces of information I'll just need spaces of the specified length to satisfy the file format. I'm using SQL 2005. Thanks in advance for any help provided.

View 4 Replies View Related

Fixed Width Output Problem

Jun 6, 2006

I'm sending the results of an SSIS data flow to an fixed-width flat file output, but instead of getting separate rows of data, like so:

row1data...
row2data...
row3data...
etc...

I get:

row1data...row2data...row3data...etc...

Is there some setting I'm missing in either the flat file output or the file connection to turn this on?

View 3 Replies View Related

Flat File Source And Destination - Need Fixed Width Output

Sep 14, 2007

I have a text file that is comma delimited and im pulling it in with a flatfile connection manager. I want to read some of the data, then output another flat file but in a fixed column width. What settings do I made to the connection manager of the output flatfile ?

View 9 Replies View Related

SSIS - Output Table To Flat Fixed-width File

Oct 19, 2007

I am new to SSIS and am having trouble with automatically setting up the destination output columns.

I am sure there must be an easy way to do this.

My table (source) has 86 columns in it of varying lenghts.

In my connection magagers, I have created one for the SQL Server (source data) and one for the flat file (destination output).

I have also created an OLE DB source data object and a destination Flat File object and set them up to the respective connection managers.

Finally I have linked the source to the destination.

Now when I look at the source, it shows me all 86 columns.

When I open up destination, there are no columns set up.

Problem: do I have to type in all the columns manually in the connection manager for the Flat File?

I would think there would be some automatic way that it would self-populate the columns over to the flat file destination.

View 3 Replies View Related

Output To Fixed Width Flat File Not Adding Line Breaks

May 19, 2008

Hi All,

I have a simple SSIS package that runs a query on the db and outputs a fixed width flat file. I have all my column widths defined and in the connection manager i can preview the output. Everything looks great. All the fields fall where they should and each record is on it's own line.

When i run the SSIS program and then go open my text file with a text editor the ouput is all on the same line. I have tried changing my file format from fixed width to ragging right and adding a row delimiter but that doesn't work either. I feel like i'm missing something small here. It could even be an issue w/ my text editor (although i've tried to open the text file in multiple editors). In the flat file connection manager I have my file defined to be 187 characters long, So figure every 187 characters it should output a new line (it should add the carraige return right?).

Has anyone encountered an issue like this?


Any help would be much appreciated.

View 4 Replies View Related

Transact SQL :: Use Print Function To Output Numeric Variable With Fixed Amount Of Leading Zeroes

Apr 23, 2015

I need to create an output from a T-SQL query that picks a numeric variable and uses the print function to output with leading zeroes if it is less than three characters long when converted to string.  For example if the variable is 12 the output should be 012 and if the variable is 3 the output should be 003.

Presently the syntax I am using is PRINT STR(@CLUSTER,3) .  But if @CLUSTER which is numeric is less than three characters I get spaces in front.

View 4 Replies View Related

Looping Through Column Types

Apr 22, 2008

Hi Everyone,

I am looking for a few pointers on how to achieve something. For the purpose
of my application I need to specify a SQL Server table. After this I wish to
be able to loop through column types and calculate the appropriate .NET
datatype based on the SQL Data Type, and also figure out if the column
allows NULL values.

I'm not looking for someone to do my work for me, just some pointers on what
I should be reading to achieve my aim.

Kind Regards

View 2 Replies View Related

Get Value By Looping Through Table Column

Apr 5, 2014

Here are two tables:

TABLE_A
[ac] [dest]
1 A
1
1
2
2
3
3 B
3

(ac=1, dest=A; ac=3, dest=B)

The space between '1' and 'A' isn't showing up correctly.

TABLE_B
[fleet] [ron]
1 A
1 A
1 A
1 A
1 A
2
2
2
2
3 B
3 B

(fleet=1, ron=A; fleet=3, ron=B; etc.etc.)

I would like to fill TABLE_B's column "ron" by referring to TABLE_A's column "dest".ac = fleet, and for each ac, I would like to loop through the 'dest' column in TABLE_A from top to bottom to get the top most value. If there are no values (like with ac = 2), then value is blank.

For 1, the value is A.
For 2, the value is blank.
For 3, the value is B.

Therefore, in TABLE_B, for all 'ron' for fleet=1, the value is filled A.
For all 'ron' for fleet=2, the value is blank.
For all 'ron' for fleet=3, the value is B.

- create variable 'v'
- where ac=fleet, loop through 'dest' from top to bottom to get top-most value. variable 'v' = the value.
- in TABLE_B, for each ac=fleet, insert variable 'v' into the 'ron' column

View 1 Replies View Related

Add Zeros For The Fixed Column

Mar 24, 2008



I would like to add right number of 0 to make the data length of varchar (14)
For example,
before after
1768 -- > 0000001768.000
23456.78 --> 0000023456.780
123679.876 --> 0000123679.876



what is the best way to do this?

View 7 Replies View Related

Using Output From A Stored Procedure As An Output Column In The OLE DB Command Transformation

Dec 8, 2006

I am working on an OLAP modeled database.

I have a Lookup Transformation that matches the natural key of a dimension member and returns the dimension key for that member (surrogate key pipeline stuff).

I am using an OLE DB Command as the Error flow of the Lookup Transformation to insert an "Inferred Member" (new row) into a dimension table if the Lookup fails.

The OLE DB Command calls a stored procedure (dbo.InsertNewDimensionMember) that inserts the new member and returns the key of the new member (using scope_identity) as an output.

What is the syntax in the SQL Command line of the OLE DB Command Transformation to set the output of the stored procedure as an Output Column?

I know that I can 1) add a second Lookup with "Enable memory restriction" on (no caching) in the Success data flow after the OLE DB Command, 2) find the newly inserted member, and 3) Union both Lookup results together, but this is a large dimension table (several million rows) and searching for the newly inserted dimension member seems excessive, especially since I have the ID I want returned as output from the stored procedure that inserted it.

Thanks in advance for any assistance you can provide.

View 9 Replies View Related

Fixed Column To Text File

Mar 19, 2008

What is the best way to export fixed length data to text file in SSIS?

View 12 Replies View Related

Looping Through Query Result Column And PRINT To Log File....

May 24, 2007

i am creating a log file, and at 1 point I record how many rows are deleted after an update process.. I want to also record which productID are actually deleted... how would I write that?!

Basically I need know how I would get the list, and I am using PRINT command... I need to somehow write a loop that works through the list and PRINTS to the file....

Thanks in advance

View 1 Replies View Related

Transact SQL :: Convert Non Fixed Rows To Non Fixed Columns Dynamically?

Oct 5, 2015

I have a table with 3 columns  (ID Int , Name Varchar(25), Course Varchar(20))

My source data looks like below

ID      Name        Course
1        A                Java
1        A                C++
2        B                Java
2        B                SQL Server
2        B                .Net
2        B                 SAP
3        C                 Oracle

My Output should look like below...

ID      Name       Course(1)     Course(2)         Course(3)     Course(4)  

1        A                 Java            C++
2        B                 Java            SQL Server .Net             SAP
3        C                 Oracle

Basically need t-sql to Convert non fixed rows to non fixed columns...

Rule: IF each ID and Name have more than 1 course then show it in new columns as course(1) course(2)..Course(n)

Create SQL:

Create table Sample (ID Int null , Name  Varchar(25) null, Course Varchar(20) null)

Insert SQL:

INSERT Sample (ID, Name, Course)
          VALUES (1,'A','Java'),
                 (1,'A','C++'),
                 (2,'B','Java'),
                 (2,'B','SQL Server'),
                 (2,'B','.Net'),
                 (2,'B','SAP'),
                 (3,'C','Oracle')

View 12 Replies View Related

Reading A Text File With Fixed Length Column

May 11, 2008

Hi,

I would like to read from a Text File using SSIS Integration Package.

The file has a fixed number of columns, let's say 3 columns.
There is no row header and each columns length is fixed. There is no delimiter as well.



Here is the sample of the file contents:
John Doe USA
Mary Monroe UK
Andy Archibald Singapore



Here is the hints to read the file contents
123456789
0123456789
0123456789
==============================
John Doe USA
Mary Monroe UK
Andy Archibald Singapore

If you notice, from the 1st column until the 9th column, it's reserved for the first name.
The 10-th column until the 19th column, it's reserved for the last name. Finally the 20-th column until the 29th column is reserved for the Origin Country.

Since there's no delimiter inside the flat file contents, i have difficulty in parsing this text using SSIS Package.

Please let me know if you need any necessary information.

Thanks for all your help.

Regards,

Hadi Teo.

View 4 Replies View Related

Add Column With Fixed Number Of Values (text) To The Select Statement

Aug 1, 2007

Hello,

I have such a problem. Need to add additional column to my query. The column should consist of set of fixed number (same as number of query rows) values (text). At start thought it's simple but now Im lost. Is there any chance to do it. Apreciate any help. I need to tell that I have only access to select on this database so no use of operation on tables.

View 6 Replies View Related

Reporting Services :: Report Viewer 10 And Fixed Column Headers

Aug 20, 2010

My problem is specific to the ReportViewer control. The report displays correctly in every other way (ssrs server viewer, visual studio preview, visual studio 'Run', etc)The aspx page hosting the control has two controls, the reportviewer control (assembly 10.0.0.0), and a scriptmanager control asyncrendering = 'true' and processingmode = 'remote'.So the columns are not 'always visible' with the reportviewer but they are with every other renderer that i've tried.

The report i'm testing is just a simple table with a couple groupings (built using the wizard). To enable the fixed headers I went to the groupings view and changed the "FixedData" property of the first Static member to true per instructions.

View 6 Replies View Related

Nesting A Looping Query Withing A Looping Query

Mar 28, 2008

Im having a issue. Im not sure how I am going to carry out but I have two tables in SQL server 2005
TABLES
     Category                    SubCategory           (PK)CategoryName      (PK) SubCategoryNameCategoryID                    SubCategoryIDDate                                Date                      (Just shows the date inserted)                                  (FK)CategoryID
On the front page, I need to have it querys out the CategoryName from Categorys but also querys out all....Well not all but atleast 5 subcategorys that relate to that categoryName. Once its down it moves to the next category and does the same and so on. Does anyone know the trick ?

View 5 Replies View Related

Max Width For Input Fixed Width Column

Jun 1, 2007

Is there a maximum width for fixed width column?

I'm trying to read in a flat file (which, admittedly, has one very wide column), and it keeps breaking because of truncation when it tries to read in the file.

Any ideas?

Jim Work

View 5 Replies View Related

How To Output Data To Different Column

Mar 12, 2013

l am fresh in SQL...

select hierarchy.hiername,devicefail.deviceid
,sum(DATEDIFF(minute,started,ended)) as duration
,100 - SUM(datediff(minute,started,ended))/(672 * 60.0000)*100 AS Uptime from devicefail
LEFT JOIN device ON device.deviceid = devicefail.deviceid
LEFT JOIN hierarchy ON device.hierlevel = hierarchy.hierlevel
where devicefail.started >= '2013-02-01 00:00:00'and
devicefail.ended <='2013-02-28 23:59:59'
and devicefail.componentid like 201 or devicefail.componentid like 0
group by devicefail.deviceid,hierarchy.hiername,devicefail. componentid
order by hiername

the above output as:

hiernamedeviceidduration Uptime
Airp 95412092548.10267857
Airp 95411891953.07787699
Airp 9542187295.35714286
Airp 9542155296.15079365

How could I achieve the result as following:

hiernamedeviceidduration1 duration2 Uptime1 Uptime2
Airp 954120925 18919 48.10267857 53.07787699
Airp 954218721552 95.35714286 96.15079365

View 1 Replies View Related

Adding A Column On Output

Sep 27, 2005

I have two queries I would like to combine the output on. they are as follows:

Select substring(WrkSta.[Name],1,2) 'Location'
,count (aexe.ReturnCode) as '# Patched'
from WrkSta, AeXEvt_AeX_SWD_Execution aexe
where WrkSta.WrkStaId=aexe.WrkStaId
and (WrkSta.[Name] like 'ES%' or WrkSta.[Name]like 'EM%' or WrkSta.[Name] like 'EP%'
or WrkSta.[Name]like 'AB%' or WrkSta.[Name] like 'SU-NP%'
or WrkSta.[Name] like 'ET%')
and (aexe.returncode='0' or
aexe.returncode ='3010')
and aexe.AdvertisementName like 'MS05-035-043%'
group by substring (WrkSta.[Name], 1,2)

---
Returns :
Location # Patched
EP 102
ES 1986
ET 19
AB 174
SU 6
EM 506

and the second one:

Select substring(WrkSta.[Name],1,2) 'Location'
,count (coll.WrkStaId ) as '# Workstation'
from WrkSta join AeXNSCollectionMembership coll on WrkSta.WrkStaId=Coll.WrkStaId
where coll.CollectionGuid = '38F5DAFC-E09D-49A5-A0FD-370983CA7596'
and (WrkSta.[Name] like 'ES%' or WrkSta.[Name]like 'EM%' or WrkSta.[Name] like 'EP%'
or WrkSta.[Name]like 'AB%' or WrkSta.[Name] like 'SU-NP%'
or WrkSta.[Name] like 'ET%')
group by substring (WrkSta.[Name], 1,2)

---
returns:

Location # Workstations
EP 178
ES 2299
ET 24
AB 215
SU 13
EM 582


What I need is :

Location # Workstations # Patched
EP 178 102
EI 2299 1986
ET 24 19
AB 215 174
SU 13 6
EM 582 582

No mater how I try to do a join to do this in a single query I end up with what looks like a cross-join and # workstations and # Patched jump to huge numbers. I obviously am having a problem understanding how to set up the select statements so that I can do this in one query or am I following the wrong direction and should be trying something else?
Once again I appreciate your help in advance....

View 1 Replies View Related

Output Column Names In Each Row Along With The Row Value

Jun 29, 2007

Hello,I was wondering if anyone can help me figure something out.Is it possible to do a querey in MS SQL server and have the resultsreturned so that each result in each row is preceeded by the columnname?eg. instead of usual output -colName1, colValue1,colName2,colValue2,colName3,colValue3 ?Also I would like to only have this for certain columns ie in theabove example only for columns 2 and 3Thank you! :-)Yas

View 4 Replies View Related

Get Name Of Column In Error Output

Apr 23, 2007

I would like to get the actual name of the column that has the error. Using the ErrorColumn (int value) I thought there would be some type of lookup collection based on the input (like column names)- if there is, can someone tell me how to get to it?

I have my error output writing to a stored proc, but instead of "32226" as the column name, I need to have the actual name of the column. I am going from Flat File to OLE DB Destination. I have a Script Component getting the output to write to my sproc, and I just need to get the column name.

Suggestions?? Thanks

View 19 Replies View Related

Output Varchar Column

May 3, 2006

Hi,

I am dumping varchar(40) column from a OLE DB Source to Excel file but it is failing due this error

[Excel Destination [239]] Error: Column "ItemDescription" cannot convert between unicode and non-unicode string data types.

How can I resolve this issue?

Thanks

View 8 Replies View Related

The Value Was Too Large To Fit In The Output Column

Mar 12, 2007

I have a Data Flow Task that extracts some data using a DataReader Source and loads it to a Raw File Destination. I am getting the following error message:

[DataReader Source [2357]] Error: The value was too large to fit in the output column "LASTCOL" (2558).

I thought that using a Raw File Destination would avoid this type of problem. How can I resolve this issue?

View 5 Replies View Related

Modify Column Output

Aug 17, 2007

using sql database, i have a smallmoney column. when i enter an amount, 50.00 for example, i have 50.0000 displayed. is there a way to only have 50.00 displayed?
same with the smalldatetime, is there a way to limit the display to "mm/dd/yyyy" without the "hh:mms am"

View 2 Replies View Related

OLE DB Source To Flat File Destintation Using Fixed Width Columns - Determining Source Column Width

Feb 13, 2007

Hi,

I am trying to create a program that transfers tables to flat files.
At this point in time, I have suceeded in created one that creates delimited files.

However, I am now trying to create fixed-width files as you can do with the SSIS designer, but programatically.

Is there a way to programatically determine the width of a column from the source table? I can not seem to find any kind of function or member that stores this information or allows me to retrieve it.

I know what I need to change in order to set a width for a column, but I just don't know how to find the width without just asking the user to provide one.

View 5 Replies View Related

Change Output Of A Column Into Hyperlink

Dec 22, 2014

I would like to change the output of a column into a hyperlink however I am not sure that is possible without some further post-processing. I am aware I would have to do:

Code:
select
'<a href="' + URL + '" target="_blank" nav="web">' + tbl_ID.ID + '</a>'
from tbl_ID
however this obviously just exports the text
<a href="[URL]" target="_blank" nav="web">[ID]</a>

This would work fine if I was exporting it into some sort of HTML table however this doesn't work with excel for example. Is there a way to make this possible or would I have to create a macro in excel to add the url with the ID separately?

View 3 Replies View Related

The Output Column Has A Precision That's Not Valid

May 5, 2008

Hi,

I'm importing data from and oracle database to an SQL one through a SSIS package, I'm getting this error:
"The output column "earned_hours" has a precision that is not valid. The precision must be between 1 and 38".
the package runs but returns this column as NULL values

earned_hours is of type "NUMBER" in oracle (some of the values are decimals), I tried making it numeric(x,y),float or decimal(x,y), but I'm still getting the same results.

does anybody know why is this happening or have a solution for this error?

Thanks

View 5 Replies View Related

BCP Output To Excel Column Width

Dec 10, 2013

I use bcp command to output to excel, it works. But I want to format the excel, some column width are too small,user need adjust the column width, otherwise it shows ######.

How can I set columns width when I use bcp output to excel.

Also, can bcp command output to multiple excel sheets and add report title in each excel sheet?

View 2 Replies View Related

Suppress Output For One Column...SOLVED

Sep 14, 2006

Is there a way to supress output on one column in a SP, using data from the same row?

Like This:
SELECT Last, First, DOP, dbo.fnDueDate(DOP, 3, GETDATE()) AS NextQDue, dbo.fnDueDate(DOP, 6, GETDATE()) AS NextNSPDue, DATEADD(m, 1, DOP)AS InitialNSPDue, DATEADD(m, 1, DOP) AS InitialAssessDue, DOT, DisReason, DATEADD(m, 1, DOT) AS DisSummDue, Facility, Active
FROM dbo.tblResidents

But which returns null for some of the columns if DOT is not null?
DOT is the Termination Date, so the only columns that have any meaning once there is data in the DOT column are DisReason and DisSummDue. Also, if DOT *is* null, then the above columns also have no meaning.
I tried several variations of the following, but I can't figure it out

CREATE PROCEDURE [dbo].[spTesting] AS
BEGIN
SELECT Last, First, DOP, dbo.fnDueDate(DOP, 3, GETDATE()) AS NextQDue, dbo.fnDueDate(DOP, 6, GETDATE()) AS NextNSPDue, DATEADD(m, 1, DOP) AS InitialNSPDue, DATEADD(m, 1, DOP) AS InitialAssessDue, Facility
FROM dbo.tblResidents A
WHERE DOT IS NULL
UNION
SELECT Last, First, DOP, DOT, DisReason, DATEADD(m, 1, DOT) AS DisSummDue, Facility
FROM dbo.tblResidents I
END
GO

----------------
-Stephen

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved