I believe I have a formatting problem in the query but I need a second set of eyes to help me please.
select @InsertSQL = ' Insert Into #ResultSet('
+ 'UserDomainMappingId,'
+ 'UserId,'
+ 'UserName,'
+ 'Domain,'
+ 'DomainName,'
+ 'LastUpdatedBy,'
+ 'LastUpdatedByName,'
+ 'LastUpdatedAt)'
select @SelectSQL = ' select '
+ 'UD.UserDomainMappingId,'
+ 'UD.UserId,'
+ '(select FullName from Users where UserId = UD.UserId),'
+ 'UD.Domain,'
+ '(select Name from ReferenceCodes RC where RC.Type = ''DOMAIN'' and RC.Code = ''' + @Domain + '''),'
+ 'UD.LastUpdatedBy,'
+ '(select FullName from Users where UserId = UD.LastUpdatedBy),'
+ 'UD.LastUpdatedAt'
select @FromSQL = ' from UserDomainMapping UD '
select @WhereSQL = 'where UserDomainMappingId = UD.UserDomainMappingId '
I'm expecting:
the select for DomainName to work, as it does if I remove the quotes and hardcode the scaler, but it doesn't inside the dynamic sql. Any ideas? Thanks.
where UserDomainMappingId = UD.UserDomainMappingId
equivalent to1=1
or did i miss something? – lakta Jul 3 '19 at 13:42PRINT
statement to generate the final query, then copy it into a query window to determine where your error is. – Eric Brandt Jul 3 '19 at 13:49NULL
, then@SelectSQL
will benull
too – lakta Jul 3 '19 at 13:52