I have a query that works perfectly but when I try to query a field that's on a joined table it doesn't apply the same way? I have a quite a few joins and most just pull fields straightforwardly. Some of the fields I have to pull from multiple rows and combine in a parent-child way into one row. Please see below....
"SELECTDISTINCTTABLEA.[Contract Number],
STUFF((SELECT'/ '+ [User Name]
FROM TABLEAT
WHERET.[Contract Number]= TABLEA.[Contract Number]ANDT.[User Role]='Admin'FORXML PATH(''),
Type).value('text()[1]','nvarchar(max)'), 1, 2, '')AS [Admin],
STUFF((SELECT' - '+ CONVERT(varchar(12),[DATE_OF_TRAINING], 107)
FROM TABLEAT
WHERET.[Contract Number]= TABLEA.[Contract Number]FORXML PATH(''),
Type).value('text()[1]','nvarchar(max)'), 1, 2, '')AS [DATE_OF_TRAINING]
FROM TABLEFRIGHTOUTERJOIN
TABLEEON TABLEF.SELLERID=TABLEE.SALES_REP_IDLEFTOUTER JOIN
TABLEDON TABLEE.PRIMCODE=TABLED.CODERIGHTOUTER JOIN
TABLEAINNERJOIN
TABLEBON TABLEA.[Contract Number]=TABLEB.[Contract Number]ON
TABLEE.C_ONUM=TABLEB.ONUMLEFTOUTER JOIN
TABLECON TABLEB.[Contract Number]=TABLEC.[Contract Number]"
This Yields
CONTRACT # Admin Date of Training
xx-xx-123 Jon Apr,28 2010 - Apr, 28,2010 - Apr,28 2010
But when I add in this filter to my second statement it yields nothing in the "date of training" column.
" STUFF((SELECT' - '+ CONVERT(varchar(12),[DATE_OF_TRAINING], 107)
FROM TABLEAT
WHERET.[Contract Number]= TABLEA.[Contract Number]ANDT.[User Role]='Admin' FORXMLPATH(''),
Type).value('text()[1]','nvarchar(max)'), 1, 2, '')AS [DATE_OF_TRAINING]"