question

Emile avatar image
Emile asked

bcp select where date between problem

The following works: bcp tkcsdb.DBO.VP_TOTALS out c:\tkcsdb.dat -n -Usa -Pabc123de and returns ~750k records. I'd like to limit the results by adding a date check against a field: SELECT * FROM DBO.VP_TOTALS WHERE ADJUSTEDAPPLYDATE between '12/16/2011' and '12/31/2011'; which returns ~1200 records when fed to DTS. I've tried dozens of variations using bcp and gotten only mixed error codes as a result. This is on Windows Server 2003 with MS SQL Server 80.
sql-server-2008bcpdatetest
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

silent_worker avatar image
silent_worker answered
bcp "select * from dbname..cm_date_lkp where businessdate between '2009-09-01' and '2010-10-01' " queryout C:\result1.csv -S servername -T -c
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bcp "select * from dbname..cm_date_lkp wher e businessdate between '2009-09-01' and '2010-10-01' " queryout C:\result1.csv -Sservername -T -c
0 Likes 0 ·
As @silent_worker has shown in the example, you need to use "queryout" option of the bcp to do that. You can see good examples in BOL e.g. http://msdn.microsoft.com/en-us/library/ms162802.aspx
0 Likes 0 ·
Emile avatar image
Emile answered
Thanks to you both. The final result was: bcp "select * from tkcsdb.DBO.VP_TOTALS where ADJUSTEDAPPLYDATE between '2011-12-16' and '2011-12-31' " queryout C:\20111231Export.csv -Usa -Pabc123de -S Labeltime -T -c
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.