Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Passing Param from Batch File to Stored Procedure
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 11/15/2012 :  21:56:15  Show Profile  Reply with Quote
Hi Sqlteam member,

Any help would be greatly appreciated.

I created a batch file that prompts for the
Begin Date and End Date as shown below.
In the .SQL program I declare the variables, however,
when I run Print statements, the values are not passing
from the batch file. Any ideas why?

@echo off

SET /P Beg_Date=Enter Begin Date:
SET /P End_Date=Enter End Date:


cd "\Documents and Settings\"

set NAME=patient_reg

@echo on

sqlcmd -s"|" -w2000 -E -Sngvrsql -dNGProd -i%NAME%.sql -v Beg_Date = '%Beg_Date%' -v End_Date = '%End_Date%' -o%NAME%_temp.txt

This the sql where I declare the variables:


DECLARE @Beg_Date AS varchar(8)
DECLARE @End_Date AS varchar(8)

PRINT @Beg_Date <-- Nothing prints here so I am not passing the values

PRINT @End_Date

--- <more code>
where Case When Len(DATEPART(mm,pe.enc_timestamp)) = 1 Then '0' + Convert(Varchar (1),DATEPART(mm,pe.enc_timestamp)) Else Convert(Varchar (2),DATEPART(mm,pe.enc_timestamp)) end +
Case When Len(DATEPART(dd,pe.enc_timestamp)) = 1 Then '0' + Convert(Varchar (1),DATEPART(dd,pe.enc_timestamp)) Else Convert(Varchar (2),DATEPART(dd,pe.enc_timestamp)) end +
Convert(Varchar (4),DATEPART(yy,pe.enc_timestamp))in (@Beg_Date, @End_Date) <--- Where I substitute the input params

In (Som, Ni, Yak)

17689 Posts

Posted - 11/16/2012 :  01:11:22  Show Profile  Reply with Quote
don't think that is how you use the variable.

Please refer to

Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000