I am running SQL express on a windows 2008 R2 server and trying to write a script to periodically query a database and save the results to a file. I have used:
sqlcmd -Q SELECT DISTINCT Date from MMD_Scale ORDER BY Date ASC -o testresults.txt
and
bcp "select distinct Date from MMD_Scale ORDER BY Date ASC" queryout testresults.txt -c -T
The problem is that both times it comes back saying the table MMD_Scale cant be resolved. I have verified the query in the Server management studio. There was also some online sources that say to specify the database with -D but when I add it it says -D is obsolete and is ignored. Any help is appreciated.