Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
We have 2 tables Tables : ApplePhone and AppleGear
Table Structure:ApplePhone
Id Phone
1 6s
2 7s

Table Structure:AppleGear
Id Gear
1 ear
2 watch

Now we need to write the above table data into flat files with | delimiter.
2 O/p File should be:
ApplePhone.dat
Id|Phone
1|6s
2|7s

AppleGear.dat
Id|Gear
1|ear
2|watch

Please help us with this if anyone has already has a code snippet.

What I have tried:

So far came up with this code:
$SQLServer = 'myServer';
$Database = 'AppleDB';
$SqlQuery = @'
Select Id,Phone FROM [AppleDB].[dbo].[ApplePhone]
'@;


Don't know how to proceed now. Newbie to this scripting world.
Posted
Updated 17-May-17 23:17pm

1 solution

You need to learn how to research topics.

Have a look at these resources:
Using Powershell to export SQL table data to text files[^]
8 Ways to Export SQL Results To a Text File - SQLServerCentral[^]
World of Whatever: Powershell export query to csv[^]
All of which I found by pasting the title of your question into Google search.
 
Share this answer
 
Comments
Member 13207333 22-May-17 0:52am    
THANKS!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900