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

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Passing Param from Batch File to Stored Procedure

Author  Topic 

ajrev42
Starting Member

1 Post

Posted - 2012-11-15 : 21:56:15
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:

d:

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:

Patient_Reg.sql

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-11-16 : 01:11:22
don't think that is how you use the variable.

Please refer to http://msdn.microsoft.com/en-us/library/ms188714.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -