Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7936741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:18:19+00:00 2026-06-03T22:18:19+00:00

Using Linq to SQL How does one query and match to include all rows

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:18:20+00:00Added an answer on June 3, 2026 at 10:18 pm

    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:

    CREATE FUNCTION dbo.SplitStrings
    (
      @List  NVARCHAR(MAX),
      @Delim NCHAR(1)
    )
    RETURNS TABLE
    AS
       RETURN ( SELECT DISTINCT Item FROM
           ( SELECT Item = x.i.value('(./text())[1]', 'nvarchar(max)')
             FROM ( SELECT [XML] = CONVERT(XML, '<i>'
             + REPLACE(@List, @Delim, '</i><i>') + '</i>').query('.')
               ) AS a CROSS APPLY [XML].nodes('i') AS x(i) ) AS y
           WHERE Item IS NOT NULL
       );
    GO
    

    Now you can say:

    SELECT t1.FAQ, t2.MODELS, t2.PIC
    FROM dbo.Table1 AS t1
    CROSS APPLY dbo.SplitStrings(t1.MODELS, ' ') AS s
    INNER JOIN dbo.Table2 AS t2
    ON     s.Item COLLATE SQL_Latin1_General_CP1_CI_AS 
      = t2.Models COLLATE SQL_Latin1_General_CP1_CI_AS
    ORDER BY t1.FAQ;
    

    Results:

    FAQ   MODELS  PIC
    ----  ------  ---------
    faq1  model1  model1pic
    faq2  model1  model1pic
    faq2  model2  model2pic
    faq3  model1  model1pic
    faq3  model2  model2pic
    faq3  model3  modal3pic
    

    The query you tried to use:

     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;
    

    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?

     SELECT t1.faqmodelnum, t1.issue, t1.resolution, 
        t2.modelnum, t2.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;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to select all columns from tables in join using linq Sql: select CTRL_RUN_JOB.*,
I am Using LINQ to query a table that has a foreign key for
I have a very complex Linq to SQL query that returns a result set
I created one asp.net mvc application using linq to sql, and in the generated
I'm using System.Data.SQLite to query a database with c#/linq . The rows I want
I'm using Linq to SQL classes in my WCF. Those classes are returned from
I have a Linq-to-Entities query that is not complicated but requires an .include and/or
I was trying Include extension method from http://damieng.com/blog/2010/05/21/include-for-linq-to-sql-and-maybe-other-providers , but it does not really
I have a particular scenario where I wrote my code using LINQ-SQL but I
Using LINQ to SQL, I have an Order class with a collection of OrderDetails.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.