0

I'm trying to set up a batch script that basically runs a SQL statement against a database, and if the script returns results it will follow some logic.

Is there a way to use a LIKE operator with % in SQLCMD Just like below. Since .bat files are treating % as a command, currently I am not getting any rows against the query.

sqlcmd -S servername -d dbname -E -Q "SELECT * from sometable WITH (NOLOCK) where col_1 like '%SE%'"
Maria
  • 41
  • 1
  • 6

1 Answers1

0

In a Batch File you can escape as:

& will be written as ^&

% will be written as %%

Two %% equals to %

In Direct CMD

& will be written as ^&

% does not need to be escaped

Dharman
  • 30,962
  • 25
  • 85
  • 135
Bilal Bin Zia
  • 596
  • 3
  • 12