Running SQL query in batch file Error.

HI All, SQLCMD -DESKTOP-SDMAAAAA\AAAAAAA DESKTOP-SDAAAA\Suresh Pasham -DelayVerification -E -Q "select * from [adv].[Route] where convert(date,CreatedDate)=convert(date,getdate())" -s "," -o "C:\Users\Suresh Pasham\source\DailySales.csv" This is my query in my batch, when I run the batch file I am getting error : Invalid object name 'adv.Route'. Outside of batch file, in sql instance it executes well. Thanks can any answer please.
6 Replies
SureshPasham
SureshPashamOP15mo ago
Can anyone answer this?
dys 🐙
dys 🐙15mo ago
I'd be amazed... Are you running a program named Suresh? I would expect it to be DelayVerification, but that's not how the command reads. Where did you get this program from?
SureshPasham
SureshPashamOP15mo ago
I am not using suresh as program name. still I get the same error Invalid object name 'DelayVerification.adv.TempRoute'. Query : select * from [DelayVerification].[adv].[TempRoute] where convert(date,CreatedDate)=convert(date,getdate()) I am thinking from batch file, how the query reads ? with schema ? Complete error in the file : Msg 208, Level 16, State 1, Server DESKTOP-SDMATQT, Line 1 Invalid object name 'DelayVerification.adv.TempRoute'.
Jochem
Jochem15mo ago
it would help to put things in a codeblock.
SQLCMD -DESKTOP-SDMAAAAA\AAAAAAA DESKTOP-SDAAAA\Suresh Pasham -DelayVerification -E -Q "select * from [adv].[Route] where convert(date,CreatedDate)=convert(date,getdate())" -s "," -o "C:\Users\Suresh Pasham\source\DailySales.csv"
SQLCMD -DESKTOP-SDMAAAAA\AAAAAAA DESKTOP-SDAAAA\Suresh Pasham -DelayVerification -E -Q "select * from [adv].[Route] where convert(date,CreatedDate)=convert(date,getdate())" -s "," -o "C:\Users\Suresh Pasham\source\DailySales.csv"
The Invalid Object Name error means that it can't find your database / table using adv.TempRoute as a target. Is adv your database? Schema? TempRoute is probably the table right? In this case, -DelayVerification is a switch to sqlcmd, which is the program being run. The DESKTOP- stuff makes it hard to parse visually
SureshPasham
SureshPashamOP15mo ago
adv. is my schema
Jochem
Jochem15mo ago
You may have to add the database name ahead of the schema, so [database].[schema].[Table]
Want results from more Discord servers?
Add your server