It is difficult to help you without knowing the table structures or seeing some sample data. However here are a couple of steps for you to find out where the problem is.
1. Highlight
SELECT GETDATE() dates,[emp code] empcode,2 types,[annual] anual FROM MEGLEAVE
and run (F5) just that section - does the error occur?
2. Do the same with
SELECT getdate(),[emp code] ,3,[sick] FROM MEGLEAVE
- does the error occur?
3. The error is most likely to be caused because one of the columns in Tbl_leave_setting is declared as Varchar(x) where x is less than 15
4. Have a look at
convert(datetime,t.dates)
- what type is column
t.dates
? - if you are trying to store a Date then it should be of type
Date
or at least
DateTime
in which case there is no need for the Convert.
Always use the most appropriate Type for the data you are trying to store, don't use Varchar (or Nvarchar, char or nchar) for anything other than alphanumeric data.