Question: While running this query

```
update p_leave_allocation_14122015 
set 'month' + @actualMonth  = @actualleavedays
where year = @actualYear  
  and emp_card_no = @emp_card_no 

```

I get an error:

> 
> Incorrect syntax near 'month'.
> 
> 
> 

The table `p_leave_allocation_14122015` has columns like `month1`, `month2`, `month3`,**.....**

In my update query what I want is `month` will be hardcoded and the no of month will be dynamic based on some conditions which I have written.

But when I tried with the above query I got the mentioned error.

I am using SQL Server 2005.

Kindly suggest

Answer: 
*You should try something like below*,

```
DECLARE @sql NVARCHAR(MAX);
SET @sql = N'update p_leave_allocation_14122015 
           SET MONTH'+CAST(@actualMonth AS VARCHAR(2)) +' = ' + CAST(@actualleavedays AS VARCHAR(10))+
           ' WHERE YEAR = '+ CAST(@actualYear AS VARCHAR(4))+
           ' AND emp_card_no = '+CAST(@emp_card_no AS VARCHAR(100)) +'';

PRINT @sql --Note: Check the query first before updating.
EXEC SP_EXECUTESQL @sql;

```
try this 

make a string and stored in `nvarchar` variable and then execute query like below

```
DECLARE @SqlQuery NVARCHAR(MAX)
SET @SqlQuery ='update p_leave_allocation_14122015 set month' + @actualMonth + '=' + @actualleavedays + ' where year = '+  @actualYear + ' and emp_card_no ='+ @emp_card_no 
EXEC(@SqlQuery)

```