October 19, 2022 at 7:13 am
Hello everyone,
I have a SQL table in which there are some columns like Name, Age, City etc.
And in rows there is some data.
Now what I am trying to do is print this data to a text file in this format:
<name>
<abc>
<age>
<44>
<city>
<Tokyo>
<phone>
<11324242>
<email>
<hj@gmail.com>
I tried various settings in flat file connection manger in SSIS package but so far no success.
Is it achievable from flat file manger or is there another way?
Check image for flat file connection manager settings.
Regards
October 19, 2022 at 7:38 am
I don't think that there is a 'no code' way of achieving this.
But if you know how to code and use Script Components, this is possible.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 19, 2022 at 7:43 am
Having said that, if you can transform your source query so that the results look like this, it would be straightforward.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 19, 2022 at 8:43 am
Keywords indeed! OK, here is one way, which (for ordering purposes) relies on every person having a unique Id column.
DROP TABLE IF EXISTS #SomeData;
CREATE TABLE #SomeData
(
PersonId INT NOT NULL PRIMARY KEY CLUSTERED
,Name VARCHAR(50) NOT NULL
,Age INT NOT NULL
);
INSERT #SomeData
(
PersonId
,Name
,Age
)
VALUES
(1, 'abc', 44)
,(2, 'def', 55);
SELECT c1.PersonId
,c1.Ctr
,c1.Item
FROM #SomeData sd
CROSS APPLY
(
SELECT x.PersonId
,x.Ctr
,x.Item
FROM
(
VALUES
(sd.PersonId, 1, '<name>')
,(sd.PersonId, 2, CONCAT('<', sd.Name, '>'))
,(sd.PersonId, 3, '<age>')
,(sd.PersonId, 4, CONCAT('<', sd.Age, '>'))
) x(PersonId, Ctr, Item)
) c1
ORDER BY c1.PersonId
,c1.Ctr;
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply