How to call user define function in sql server -


i'm creating query in sql server 2014

declare @ff varchar(33) set @ff='day'+cast((select day('2011-04-02')) varchar(2)) print @ff update customer set day1='p' userid=12 update customer set @ff=''+'f'+'' userid=15 print @ff select * customer 

it gives message 1 row effected there no change take place in table. please me solve problem

you can't use variable column name in way do, second update needs done dynamic sql statement inject variable query string this:

declare @sql nvarchar(max) set @sql = n'update customer set ' + @ff + ' = ''f'' userid=15' exec sp_executesql @sql 

with variable @ff defined as:

declare @ff nvarchar(33) set @ff='day'+cast((select day('2011-04-02')) varchar(2)) 

this update column day2 have value f userid = 15

you rid of @ff variable , build query string directly:

set @sql = concat(n'update customer set day', day('2011-04-02'), ' = ''f'' userid=15') 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -