sql server - Error converting data type varchar to datetime. Need to return records based on the date or all records if no date is specified -
i have implemented storedprocedure , want storedprocedure return records if no parameter sent or records based on parameter sent. using date parameter. getting error when executing exec [dbo].[getlog] '27/07/2017'
. error
error converting data type varchar datetime.
could tell me incorrect in logic
create procedure [dbo].[getlog] @datefrom datetime begin -- set nocount on added prevent result sets -- interfering select statements. set nocount on; select * [coreanalytics].[dbo].[logs] [timestamp] > isnull(@datefrom, 0) ; end go
if understand correct want return records if @datefrom null, or filter on variable.
think need then
create procedure [dbo].[getlog] @datefrom datetime begin -- set nocount on added prevent result sets -- interfering select statements. set nocount on; select * [coreanalytics].[dbo].[logs] (@datefrom null or [timestamp] > @datefrom) end
make sure passing valid datetime when calling procedure.
best use universal format work database,
yyyymmdd format work. see http://www.karaszi.com/sqlserver/info_datetime.asp#dtformatsinput
exec [dbo].[getlog] '20170727'
should work
Comments
Post a Comment