Query is bahaving different with osql and sqlcmd

The attached Sql is behaving different

when I run it using osql there is no error
When I run using sqlcmd the error is 'Incorrect syntax near 'go'.'

Can some one help this . Is there any special character that I can use to avoid this error

 2.txt 2.txt
vijay11Asked:
Who is Participating?
 
Daniel ReynoldsConnect With a Mentor Software Applications Developer / IntegratorCommented:
check this out... http://msdn.microsoft.com/en-us/library/ms162773.aspx

It shows a way to keep the osql scripts compatible.


Note
The OSQLUSER environment variable is available for backward compatibility. The SQLCMDUSER environment variable takes precedence over the OSQLUSER environment variable. This means that sqlcmd and osql can be used next to each other without interference. It also means that existing osql scripts will continue to work.
 
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Break each command into separate commands and send them to sqlcmd separately.

The go statement signifies a break as to where a statement ends.

You could also try just putting an ;  instead of the go statement. the semi-colon can also act (it used to at least) as a statement separator. But most likely you will need to send each command separately.
0
 
vijay11Author Commented:
Is there any other way I can get this working with out changing the code , because now I have to change may be 1000 sql scripts . we have been using osql from years , but suddenly a client wants sqlcmd to execute this . Is there any other way

Thanks
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
vijay11Author Commented:
I get error hen I execute from sql server management studio also , but from sql 2000 query analyzer I dont get error
0
 
vijay11Author Commented:
Now I am using

sqlcmd -U -P -S -dmark -i'c:\2.sql' -o'c:\2.log'

How I have to change the above command to make this script work.Please help me
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
So, these queries were written for SQL 2000 and now they are being ran against SQL 2008?
0
 
vijay11Author Commented:
In sql 2008 also If i run using osql Every thing runs fine and The query works fine

Thanks
0
 
Vadim RappCommented:
To begin with , the following statement in what you posted clearly has syntax error, an extra single quote:

Exec pr_prim_key 'country, @EntityID output

so everything that follows is treated as literal, and so it couldn't be valid in osql. It looks like what you posted is not what you run, is it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.