SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 File Format
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wsilage
Yak Posting Veteran

USA
74 Posts

Posted - 08/26/2014 :  14:41:07  Show Profile  Reply with Quote
I have a SQL table that I need to export into a file. The requirements need to be this...

File should be pipe ("|") delimited .txt file with date in filename (CCYYMMDD)

How can I do that?

My Query that I have is like this that goes into my table Unless, this portion doesn't matter, but I wanted to share with you.



SELECT Distinct

LEFT([First Name],100) [First Name],
LEFT([Last Name],50) AS [Last Name],
LEFT([Product],40) AS [Network],
LEFT([Degree],10) AS [Title],
LEFT([Tax ID],9) AS [TAX ID],
LEFT([Address 1],75) AS [Address 1],
LEFT([Address 2],75) AS [Address 2],
LEFT([City],25) as [City],
LEFT([St],2) AS [ST],
LEFT([Zip],10) AS [ZIP],
LEFT([COUNTY],100) AS [County],
LEFT([Phone],12) AS [Phone],
CONVERT(varchar(10), [Effective Date], 112) AS [Provider Effective Date], ---CCYYMMDD
CONVERT(VARCHAR(10), [Termination Date], 112) AS [Provider Termination Date], ---CCYYMMDD

Case

When [Address 1] = [Billing Address] or [pro_btag] = 'Y' Then 'P'
Else ''
End as [Location Type],

LEFT([Spec 1],50) AS [Primary_Specialty],
LEFT([NPI],40) as [Physician_NPI],
LEFT([PCS Number],40) as [Provider_Key],
LEFT([PRO ID],40) as [Sequence_Key]

From vw_test

tkizer
Almighty SQL Goddess

USA
37142 Posts

Posted - 08/26/2014 :  15:01:15  Show Profile  Visit tkizer's Homepage  Reply with Quote
bcp YourDb.dbo.YourTbl out c:\temp\YourTbl_20140826.txt -T -Sserver1\instance1 -c -t"|" -r\r\n


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

wsilage
Yak Posting Veteran

USA
74 Posts

Posted - 08/26/2014 :  15:14:32  Show Profile  Reply with Quote
bcp MonthEnds.dbo.HMHP out c:\temp\YourTbl_20140826.txt -T -bisql\instance1 -c -t"|" -r\r\n

I added my info, but I am getting an error saying below

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '.'.







quote:
Originally posted by tkizer

bcp YourDb.dbo.YourTbl out c:\temp\YourTbl_20140826.txt -T -Sserver1\instance1 -c -t"|" -r\r\n


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/

Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37142 Posts

Posted - 08/26/2014 :  15:24:57  Show Profile  Visit tkizer's Homepage  Reply with Quote
You need to run it from a command prompt. (Start..Run..cmd)

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000