Good morning everyone. Wondering if anyone can help me out. I am trying to write a batch file to make my life and others lives easier in my job but wanted to seek out some help. I typically run a bunch of different SQL scripts that I wrote to install a particular installation and decided life would be easier if i moved these all to batch files. I am trying to run the following command from a batch file:
:T02
cls
echo Qualifiers will be installed next with names of
echo Q_AutoFax_CC_1
echo Q_AutoFax_CC_2
echo Q_AutoFax_CC_3
echo Q_AutoFax_CC_4
echo Q_AutoFax_CC_5
pause
cls
If Exist "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe" cd "C:\Program Files\Microsoft SQL Server\100\Tools\Binn"
If Exist "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\bcp.exe" cd "C:\Program Files\Microsoft SQL Server\90\Tools\Binn"
If Exist "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp.exe" cd "C:\Program Files\Microsoft SQL Server\80\Tools\Binn"
sqlcmd /U eiw_admin /P eiw_admin /d cabinet /S . /Q
"declare @q int
select @q = 1
While @q < 6
Begin
Insert into cabinet..qualifiers
select 'HL7', 'Q_AutoFax_CC_'+ convert(varchar(2),@q),
'%Physician_Code'+ convert(varchar(2),@q)+'% == (NULL) || %Physician_Code'+ convert(varchar(2),@q)+'% == (BLANK)', 'R'
select @q = @q + 1
End"
pause
cls
I typically run just:
declare @q int
select @q = 1
While @q < 6
Begin
Insert into cabinet..qualifiers
select 'HL7', 'Q_AutoFax_CC_'+ convert(varchar(2),@q),
'%Physician_Code'+ convert(varchar(2),@q)+'% == (NULL) || %Physician_Code'+ convert(varchar(2),@q)+'% == (BLANK)', 'R'
select @q = @q + 1
End
from SQL and it runs just fine...i have used SQL commands before in a batch file...is there something different that needs to be done for this one since it is a loop and not a generic command? The file is being ran from the database server and I am getting an error:
Sqlcmd: '-Q': Missing argument. Enter '-?' for help. ' "declare @q int' is not recognized as an internal or external command, operable program or batch file
.....same thing with select, begin, insert and select....etc
I thought if you ever wanted to run SQLCMD, you just had to put your command in single quotes, is this not correct?