Saturday, February 25, 2012

Pass datetime as parameter to SP

my SP like this
CREATE PROCEDURE dbo.sel_apinv_nonsettle
@.cocode varchar(10),
@.billcode varchar(10),
@.issuedate datetime,
@.branchid varchar(10),
@.accttype varchar(10)
IN SQL Analyzer,
exec sel_apinv_nonsettle 'CNC','CNC',getdate,'HLSHK','APINV'
and i got this error "Server: Msg 8114, Level 16, State 4, Procedure
sel_apinv_nonsettle, Line 0
Error converting data type nvarchar to datetime."
What's wrong 'Hi
Probably you need to put it this way
IN SQL Analyzer,
exec sel_apinv_nonsettle 'CNC','CNC',getdate(),'HLSHK','APINV'
getdate() is a function
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.examnotes.net/gurus/default.asp?p=4223
---
"Agnes" wrote:

> my SP like this
> CREATE PROCEDURE dbo.sel_apinv_nonsettle
> @.cocode varchar(10),
> @.billcode varchar(10),
> @.issuedate datetime,
> @.branchid varchar(10),
> @.accttype varchar(10)
> IN SQL Analyzer,
> exec sel_apinv_nonsettle 'CNC','CNC',getdate,'HLSHK','APINV'
> and i got this error "Server: Msg 8114, Level 16, State 4, Procedure
> sel_apinv_nonsettle, Line 0
> Error converting data type nvarchar to datetime."
> What's wrong '
>
>|||Stored Proc Parameters can only be constants, or T-SQL Variables... You cnno
t
directly pass an expression, or a function, to a stored proc... And even if
you could, the function getdate would require the open closed parenethses at
the end -- getdate()...
What you need to do is create a T-SQL Variable, set it to be equal to
getdate(), and then pass that variable.
Declare @.GDT DateTime
Set @.GDT = getdate() -- ("Current_TimeStamp" is ANSI-SQL Standard)
exec sel_apinv_nonsettle 'CNC','CNC',@.GDT,'HLSHK','APINV'
exec sel_apinv_nonsettle 'CNC','CNC',getdate,'HLSHK','APINV'
"Agnes" wrote:

> my SP like this
> CREATE PROCEDURE dbo.sel_apinv_nonsettle
> @.cocode varchar(10),
> @.billcode varchar(10),
> @.issuedate datetime,
> @.branchid varchar(10),
> @.accttype varchar(10)
> IN SQL Analyzer,
> exec sel_apinv_nonsettle 'CNC','CNC',getdate,'HLSHK','APINV'
> and i got this error "Server: Msg 8114, Level 16, State 4, Procedure
> sel_apinv_nonsettle, Line 0
> Error converting data type nvarchar to datetime."
> What's wrong '
>
>

No comments:

Post a Comment