sql server - Pass parameters to a procedure with SQLcmd -


i use sql command:

 sqlcmd -v first_date="30/09/2015" last_date="15/09/2016" 

the sql execute:

declare @return_value int  exec    @return_value = [dbo].[_testprocedure]  select  'return value' = @return_value  go  print 'finally' go 

and pass parameters stored procedure:

alter procedure [dbo].[_testprocedure]     execute caller begin      declare @f_first_date_dt varchar(50)     declare @f_last_date_dt varchar(50)      set @f_first_date_dt = n'$(first_date)'     set @f_last_date_dt = n'$(last_date)' 

but return me error:

incorrect syntax near 'first_date'

what correct way pass variables stored procedure?

if declare @f_first_date_dt , @f_last_date_dt input parameters of stored procedure - able call

exec @return_value = [dbo].[_testprocedure]                           @f_first_date_dt = $(first_date),                           @f_last_date_dt = $(last_date) 

in script you're running sqlcmd.

you're getting error because $() syntax valid accessing external varables in sqlcmd script, , not in stored procedures.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -