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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Daniel ReynoldsSoftware 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.