Using Linq to SQL
How does one query and match to include all rows from a secondary table with a column that contains spaces in column?
Table 1:
ID FAQ MODELS
1 faq1 model1
2 faq2 model2 model1
3 faq3 model3 model2 model1 (Spaces in models column)
Table 2:
ID MODELS PIC
1 model1 model1pic
2 model2 model2pic
3 model3 modal3pic
Expecting:
faq1 model1 model1pic
faq2 model1 model1pic
faq2 model2 model2pic
faq3 model1 model1pic
faq3 model2 model2pic
faq3 model3 model3pic
SELECT kwfaqtmp.faqmodelnum, kwFAQtmp.issue,
kwfaqtmp.resolution, kwtable4tmp.modelnum,
kwtable4tmp.prodpic
FROM kwfaqtmp AS t1 CROSS APPLY dbo.SplitStrings(t1.faqmodelnum, ' ') AS s
INNER JOIN dbo.kwtable4tmp
AS t2 ON s.item COLLATE SQL_Latin1_General_CP1_CI_AS = t2.modelnum
COLLATE SQL_Latin1_General_CP1_CI_AS
ORDER BY t1.issue;
If you can’t fix the design (you shouldn’t be storing multiple pieces of data in a single column, as pointed out elsewhere), you can accomplish this with a split function:
Now you can say:
Results:
The query you tried to use:
Is simply not valid. Though it shouldn’t yield the exact error you cite in the comment. How about keeping the t1 / t2 aliases as my original query showed?