declare @ownerId int = ; declare @ownerType varchar(3) = ; with data as ( select clientSegId, segAbbrv, parentSegmentName, segmentName, segmentPath, hierarchyLevel, segmentId as oneFSSegmentId, segmentName as clientSegName, segmentPath as clientSegPath , hasChildSegments from tbl_OPR_ClientSegments with (nolock) where ownerId = @ownerId and fsl_tablecode = @ownerType ) #forJSON( 'data', attributes.dataStore, 'segmentPath' )#