Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
alter  procedure test 
 (
 @t1 varchar(50),

@emplrid  varchar(15),
@emp_doj date,
@emp_desg varchar(50),
@emp_type varchar(50),
@emp_locid varchar(15),
@dept_id varchar(50),
@emp_reportingto varchar(50),
@emp_batchno varchar(50),
@emp_cardno varchar(50),
@emp_weekoff varchar(50),
@emp_ctc varchar(50),
@emp_opngctc varchar(50),
@cdate date,
@esi_subcode varchar(50),
@emp_id varchar(15)
)
 as
 begin
 
 DECLARE @SQL varchar(250)
 
 SELECT @SQL = 'insert into ' + @t1 + ' values ('''+@emp_id+''','''+@emplrid+''','+@emp_doj+','''+@emp_desg+''','''+@emp_type+''','''+@emp_locid+''','''+@dept_id+''','''+@emp_reportingto+''','''+@emp_batchno+''','''+@emp_cardno+''','''+@emp_weekoff+''','''+@emp_ctc+''','''+@emp_opngctc+''','+@cdate+','''+@esi_subcode+''')'
 
 EXEC (@SQL)
    
 end 

ERROR:
Msg 402, Level 16, State 1, Procedure test, Line 26
The data types varchar and date are incompatible in the add operator.
Posted
Updated 18-Feb-14 1:18am
v2

The error message is self explanatory. You are trying to concatenate a date with a varchar (string).
Use CAST OR CONVERT[^] to convert date to a varchar.
So in your case, just change @cdate part to CAST(@cdate AS varchar(15)) and it should be fine.

Hope that helps!
 
Share this answer
 
Update your query to use
Cast(@emp_doj as varchar(10) and Cast(@cdate as varchar(10)
 
Share this answer
 
Comments
ravikiran geddam 19-Feb-14 1:41am    
thank you very much guys . i also asked about image datatype . please send me that also .
Gauri Chodanker 20-Feb-14 7:52am    
Your query did not state anything of image.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900