0

I am querying a Sybase SQL Anywhere 17 database to get a count from a table, and outputting that count (number) to a txt file. Running in cmd window is fine, but running via batch script gives a different result.

The following works exactly as it should via Windows cmd line:

dbisql -datasource=DATABASEHERE -c "UID=USERNAMEHERE;PWD=PASSWORDHERE" SELECT COUNT(*) FROM "DRSYS"."Online" WHERE Status LIKE 'S%'; OUTPUT to OnlineUnreadCount.txt

Let's say that output is "190"

However, when running it via batch script, which is:

@echo off 
dbisql -datasource=DATABASEHERE -c "UID=USERNAMEHERE;PWD=PASSWORDHERE" SELECT COUNT(*) FROM "DRSYS"."Online" WHERE Status LIKE 'S%'; OUTPUT to OnlineUnreadCount.txt

It runs and outputs, but the number in the txt file is "133" instead of the expected "190". What am I doing wrong? I cannot see where the difference is.

Stephen Quan
  • 21,481
  • 4
  • 88
  • 75
  • 2
    Perhaps the % is being interpreted by batch and is being replaced before it is sent to dbisql. Perhaps % needs to be escaped? Try %% instead? – Stephen Quan Apr 10 '23 at 22:39
  • @StephenQuan you’re exactly right. That never once crossed my mind, and it should have. Thanks man! – Mark Jones Apr 11 '23 at 03:10

0 Answers0