sql function in cmd

gholamreza rezaie 61 Reputation points
2022-02-23T15:24:00.263+00:00

hello my friends .. if any windows have not ssms i ask that we can change database in cmd by this code:
sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt

but when i use this in cmd i have a error that say :
Could not find files for the given pattern(s).

for example this below code is my script that i write in ssms and change my database but when i test in cmd i have that error

UPDATE [fmk].[user] set [Password]='212-29-140-217-143-0-178-4-233-128-9-152-236-248-66' where UserID='1'

177180-sql-in-cmd.jpg

i think that i had bad replace and do it wrong.

thanks for your answers my friend.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,663 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tom Phillips 17,731 Reputation points
    2022-02-23T16:51:24.177+00:00

    To run a query in sqlcmd, not a file, you use "-Q". See:
    https://learn.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15

    SQLCMD -S .\sepidar009 -Q "UPDATE......"  
    
    0 comments No comments

  2. YufeiShao-msft 7,116 Reputation points
    2022-02-24T07:02:51.963+00:00

    Hi @gholamreza rezaie ,

    Could not find files for the given pattern(s)
    You need enclose the command in "……“(double quotes), otherwise the script will not run

    USING SQLCMD UTILITY TO RUN SQL STATEMENTS FROM COMMAND LINE

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.