Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 914959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:48:22+00:00 2026-05-15T17:48:22+00:00

I am experiencing some strange behavior with OSQL, and would appreciate any help. I

  • 0

I am experiencing some strange behavior with OSQL, and would appreciate any help.

I have a batch file that will copy a database field from one column to another. Here is a sample script:

SET NOCOUNT ON; 
UPDATE Table1 SET Table1.EmailAddress = Table2.GenericField FROM Table1
INNER JOIN Table2 ON Table1.ID = Table2.ID WHERE GenericField LIKE '%@%.%' 
   AND EmailAddress IS NULL;
SELECT @@ROWCOUNT;

Assuming all the EmailAddress fields are NOT NULL anymore, I would expect the update statement to return a @@ROWCOUNT of 0.

  • Example 1:

Running the above query in Query Analyzer gives me 0 for the @@ROWCOUNT. That’s good.

  • Example 2:

Test.Sql contains the exact same SQL statement as above. If I use the following OSQL statement, I also get a 0 for the @@ROWCOUNT:

osql.exe -D TestConn -U UserID -P pwd -s , -h-1 -w 100 -n ^
    -i "C:\Scripts\Test.sql"
  • Example 3:

If I have the SQL statement in the batch file instead of a SQL file, I get a @@ROWCOUNT of 2:

osql.exe -D TestConn -U UserID -P pwd -s , -h-1 -w 100 -n -Q ^
  "SET NOCOUNT ON; 
   UPDATE Table1 SET Table1.EmailAddress = Table2.GenericField FROM Table1
   INNER JOIN Table2 ON Table1.ID = Table2.ID WHERE GenericField LIKE '%@%.%' 
      AND EmailAddress IS NULL;
   SELECT @@ROWCOUNT;" 

Do I have a switch set wrong for example 3? Why would I suddenly get a @@ROWCOUNT of 2 instead of 0?

The first time I ran the script, I got a @@ROWCOUNT of 5, when only three records were updated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:48:23+00:00Added an answer on May 15, 2026 at 5:48 pm

    Batch files expand % to a variable. You can escape it by using double %%s:

    WHERE GenericField LIKE '%%@%%.%%' 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experiencing some strange behavior for which I can't find any documented knowledge. Here's
I am experiencing some strange behavior with SQL Server CE 3.5 SP2. I have
I am experiencing some strange behavior in my datagrid when I have a second
I am experiencing some very strange behavior with Blend: Since weeks i am working
I am experiencing some strange behaviour and I really don't have test date/ environments,
I'm experiencing some strange behavior with a project i'm working on: http://daft.net76.net/yah/ When you
I have the following class in a Windows Service that is experiencing some vary
I experiencing a strange behavior of C#. Its some thing like this.. var date
I am experiencing strange behavior using git stash, I have two branches v0 and
I'm experiencing some strange behavior with .bind() and .unbind() in JQuery, even though my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.