0

I'm trying to run an osql command from a cmd shell. I need to use a cmd level variable within my osql command.

For example, I have a variable %mydate%, and I want to pass it in as the value for the @start_date parameter in the following osql call.

osql -Sdb -Uautosys -Pdata_load -ddms -Q"EXEC dbo.sp @start_time = '' "

How can I do this?

TIA!

chama
  • 5,973
  • 14
  • 61
  • 77

1 Answers1

1

Have you tried this?

osql -Sdb -Uautosys -Pdata_load -ddms -Q"EXEC dbo.sp @start_time = '%mydate%' "

dos substitution happens quite early, so osql shouldn't see the actual string %mydate%

gbn
  • 422,506
  • 82
  • 585
  • 676
  • That's what I was trying, but it didn't work. I assumed that I had the wrong method of doing it. Turns out that my variable was null, so I was having problems. Do you know how to concatenate two variables in a cmd shell? Maybe I'll post that as a different question... – chama Nov 22 '10 at 19:27
  • 1
    @chama: SET foo = %firstOne%%SecondOne% – gbn Nov 22 '10 at 19:28
  • That's what I thought, but it doesn't work. My code is `set mydate2 = %mydate%%Time%`. – chama Nov 22 '10 at 19:32
  • @chama: %Time% is special/reserved. Was this intended? http://www.computerhope.com/sethlp.htm. And thank you for the rep :-) – gbn Nov 22 '10 at 19:45
  • 1
    Might have just needed a space, e.g. `set mydate2 = %mydate% %Time%` – Philip Kelley Nov 22 '10 at 19:46