SQLTeam.com | Weblogs | Forums

Dynamic Pivot Invalid Column error


#1

Hello All

I am building another Dynamic Pivot script.

But as I am building the column names in a variable, I get a column name with the red wiggly line saying invalid column name. see below

Declare @Prop_ID int
, @DynamicPivot as Nvarchar(max)
, @DynamicColumns as Nvarchar(max)

set @DynamicColumns =N'';

  set @DynamicColumns += N', [' + Account_Number + ']'

from (select [Account_Number] from Schedule.Property_Underlease
)as c;

i know the Schedule.Property_Underlease table exists with the Account_Number column

and i also get an error at "From" and "as" with incorrect syntax, i don't understand i have used this format a good handful of times

can someone please help

Regards

ROb


#2

its ok, ive sorted it,

changed the following

set @DynamicColumns += N', [' + [Account_Number] + ']'

to

select @DynamicColumns += N', [' + [Account_Number] + ']'

Cheers anyway