sql server - conversion failed when converting date /time from character string -
select [proc_id] ,[contact_date_new] ,[cpt_code_new] ,[chargeable_yn_new] ,cat.cdm_category ,dateupdated [dbo].cdm_audit_eap_ot] @coldate between @start_date , @end_date
after add new parameter @coldate
, start getting above error.
@coldate
has "contact_date_new" or "dateupdated". users choose either 1 depend on looking for.
if specify column directly, report work fine.
contact_date_new between @start_date , @end_date dateupdated between @start_date , @end_date
the @coldate
in query not treated column name, instead string type variable. when try compare values @startdate
, @enddate
fails. hence error. can create stored procedure follows suit need :-
create procedure [ssrsreport] @start_date date, @end_date date, @coldate nvarchar(25) begin set nocount on declare @sql1 nvarchar(max) if @coldate = 'contact_date_new' begin set @sql1 = 'select [proc_id] ,[contact_date_new] ,[cpt_code_new] ,[chargeable_yn_new] ,cat.cdm_category ,dateupdated [dbo].cdm_audit_eap_ot] contact_date_new between ''' + cast(convert(nvarchar(10),@start_date ,120) nvarchar(max)) +''' , ''' + cast(convert(nvarchar(10),@end_date ,120) nvarchar(max)) + '''' end else if @coldate = 'dateupdated' begin set @sql1 = 'select [proc_id] ,[contact_date_new] ,[cpt_code_new] ,[chargeable_yn_new] ,cat.cdm_category ,dateupdated [dbo].cdm_audit_eap_ot] dateupdated between ''' + cast(convert(nvarchar(10),@start_date ,120) nvarchar(max)) +''' , ''' + cast(convert(nvarchar(10),@end_date ,120) nvarchar(max)) + '''' end print @sql1 exec sp_executesql @sql1 end
Comments
Post a Comment