SQL Server 2005- "Copy Direction must be in, out or format" - sql-server-2005

I wrote a program in early 2010 that ran a command line function that pulled data from SQL Server 2005. The program worked at the time, but does not seem to work now (for various reasons, it was not used for about a 1 year).
BCP "EXEC emdb..Patch2" QUERYOUT D:\shares\patch2.txt -S GEN-SERVER\EMMSDE -t "~" -c
The error message says "Copy direction must be in, out or format." I'm trying to figure out what I need to change to make this work; Please note that I don't actually have any programming background (it was extensive research into books that my boss no longer has). Thanks,

Related

Way around the bcp/freebcp queryout Long Query String error

It's an old bug fixed in Microsoft's Q279180, that can no longer be viewed. In fact, you get that sardonic response from them.
We would like to show you a description here but the site won’t allow us.
1 - 1
https://support.microsoft.com/en-US/search/results?query=Q279180
I'm working with a very restricted read-only sources (SQL Server DBs) and no root access to mod client options on Unix; so my idea was to use the freebcp from FreeTds in the queryout mode to submit a joined sql for an extract. And of course this won't allow anything above some puny 100 characters for a query text.
Wonder, if anyone has found a way around it.

How do you write queries in SQL?

I am currently taking CS50, an online introductory course in coding by Harvard. We have just covered SQL and I am trying to attempt the question "Movies" in the problem set now, a description of which can be found here: https://cs50.harvard.edu/x/2020/psets/7/movies/
However, I am not sure how to do this correctly.
For example, for 1.sql, my code is as follows:
SELECT title FROM movies WHERE year = 2008;
I literally wrote only that one line and nothing more in the file "1.sql".
But when I run
$ cat 1.sql | sqlite3 movies.db
in my terminal, nothing happens?
Is this how I am supposed to write code for SQL? Or am I missing some stuff that I should be including (e.g. as headers or what) above my query?
To be clear, I believe I know how to write a query itself but I do not know the "protocol" to write it, if I may. I mean, for example, I am positively sure that "SELECT title FROM movies WHERE year = 2008;" fulfils the question's first requirement.
Some enlightenment would be appreciated!
EDIT 1
Okay first I must apologise to everyone who so very kindly took the time to comment on my post. For some very odd reason, my query did not return any results the first time I ran it. However, when I tried it again, it worked perfectly! Not sure what went wrong honestly, but all is well now! So sorry for wasting everyone's time ):
EDIT 2
Okay I also figured out that the reason why I could not execute my query is that I was in "sqlite3" in my terminal. I was supposed to run the command to execute my query in the main terminal i.e. not when it says "sqlite3". Stupid. I know.
Option 1) you can run "$ cat 1.sql | sqlite3 movies.db" in your normal terminal (not in the sqlite3 mode)
Option 2) you can open sql environment by typing "sqlite3 movies.db" (it will open movies.db if it exists, or create a temporary one if it doesn't exist). Then you can type ".read 1.sql" after the "sqlite>"
Open Browser and test it as mention on your course site
Usage
To test your queries on CS50 IDE, you can query the database by running
$ cat filename.sql | sqlite3 movies.db
where filename.sql is the file containing your SQL query.
Or you can paste them into DB Browser for SQLite’s Execute SQL tab and click ▶.

Recover unsaved SQL query Scripts in Oracle SQL Developer

I know how to do this in SQL Server thanks to this clever bit of code
Use <database>
SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script]
FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY execquery.last_execution_time DESC
SOURCE:
Recover unsaved SQL query scripts
Is there a way to do this in Oracle SQL Developer?
This has saved my butt several times.
It is really a problem when you lose unsaved code. For about a
month I have been working on a big procedure, and forgot to save the
code in SVN. If you read this and remember have such unsaved code,
commit it immediately! :) Because everything could happen with your
test db. Ok. you're lucky if you were using Oracle SQL Developer,
because this program has a great feature - it saves your code in its
sql history inspite of eating a big party of your RAM. Open your file
explorer and locate this folder:
C:\Users\%USERNAME%\AppData\Roaming\SQL Developer\SqlHistory
You'll find a lot of XML files, and if you're twice lucky, you'll find
your lost code. It's wonderful. :) . If you're using another program,
try to find a feature like this and maybe it helps you. My condolences
if this post doesn't help you, in any case, try to find something good
among the next: 1) write your code again, and it will be better than
before as you did it once 2) commit your code, so you'll not face such
problem in the future
If you have the privileges then:
SELECT * FROM v$sql
If not then press F8 to bring up a list of previously ran queries.
You can try too, so you can get the unsaved SQL.
View > SQL History, for example, look this picture:
This is using SQLDeveloper's history, like in Matt's answer, but if you want to search through the history files for specific query fragments you remember, they are located as .xml files in /home/username/.sqldeveloper/SqlHistory. From there, enter:
find -type f -mtime -1 -print0 | xargs -0 grep -l <text>
(where -mtime -1 means no sooner than one day ago).
Through View> SQL History or by pressing F8 is a great way to do it, it lets you search for content or database connection, really a good implementation!
SQL History
Use the undo button, as shown in the image

SQL Username drives me crazy

I am on this tutorial: http://www.postgresqltutorial.com/load-postgresql-sample-database/
I'm doing everything described in psql, but I always fail when it comes to the username input. What am I doing wrong here?
Screenshot with error message is here:
Thanks for your help.
(Caveat: I'm unfamiliar with Windows psql, but I'm familiar with the Linux psql)
When starting up psql in the manner that you're describing, you just have to press enter a few times. The server, database, port and username are already filled in with the values in square brackets, so pressing enter will use those values. Once you get to a prompt that looks like this:
postgres=#
...then you can run theCREATE DATABASE dvdrental; command.
After creating the database, type \q to return to your Windows command line (may not apply, in which case, open a fresh Windows command line)". From here, you can follow the rest of your tutorial starting at "Load the DVD rental database"

Help with DB2 Error when trying to execute SQL

I started using the system with a pre-made file called DB2.SQL. I am using this because it is what the tutorial said to use. I then edited this file and replaced the contents with my own code:
CREATE DATABASE BANKDB13 BUFFERPOOL BP0;
When I try to execute a SQL it though, I get this error:
DSNE377A INPUT DATA SET RECFM MUST BE F OR FB WTIH LRECL 80
What does this error mean and how do I correct it on the file?
I am running it with Vista TN3270 on Windows 7 over TSO, in SPUFI mode.
What I've tried so far:
When I start editing the file, I have a screen to change the defualts, and I have changed the RECORD FORMAT to F and FB as well as setting the RECORD LENGTH to 80 with no success.
EDIT:
I resolved the problem by deleting the DB2.SQL file and recreating it, and also making sure that the sizes I gave for the files were consistent with each other.
What SQL are you trying to execute on it?
The error means that the Record Format in the input data set must be either "F IXED" or "F IXED B" LOCK with a logical record length of 80.
So this is what the error means, how to correct it depends on the SQL you're running and the desired outcome.
What Tutorial is it that you refer to, do you have a link? Is this a real world problem, homework or you expanding your knowledge into mainframe DB2?
Your SQL snippet above is creating a DB, what is the INPUT DATASET file format that you are subsequently running SQL on?