I have problem inserting sql script in the variable.I have this code
declare @result_var varchar(max);
SET @result_var='';
DECLARE @cursor CURSOR,
@name VARCHAR(100)
SET @cursor = CURSOR
FOR SELECT [NAME]
FROM [iflvs08].mds.mdm.lv_budget_employee
OPEN @cursor
FETCH next FROM @cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
IF (RIGHT(@Name, 1) = ' ')
begin
IF( Len(@result_var) > 1 )
SET @result_var=@result_var + ','+ @name
ELSE
SET @result_var=@name
END
FETCH next FROM @cursor INTO @name
END
I want to insert into variable it but when try to insert it like this
set @sql='code here'
It get confuse whit this ' symbol and dont insert it I always get error like this Msg 102, Level 15, State 1, Line 13 Incorrect syntax near ' begin IF( Len(@result_var) > 1 ) SET @result_var=@result_var + '.