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

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

ajrev42
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:

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)

Singapore
17681 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 http://msdn.microsoft.com/en-us/library/ms188714.aspx


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000