Results 1 to 3 of 3

Thread: [RESOLVED] [2005] SQL IN statement question

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Resolved [RESOLVED] [2005] SQL IN statement question

    I think I have an idea about how to do this, just looking for some input. I think I have to do 2 queries. The first query gets the distinct values in a table which returns a list of integer values. I would then want to use these numbers in the 2nd query.

    Any number of values could be returned from query1. My question is how do I use that info in query 2? I think I have to use the IN statement. Do I have to use commandbuilder because I don't know how many results will be returned?

    query1:
    2 Code:
    1. SELECT DISTINCT myCol1 FROM someTable

    query2:
    2 Code:
    1. SELECT * FROM otherTable WHERE myCol IN (int1, int2, int3, int4.....)

    How do I construct the IN part with the results returned from query1 ?
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] SQL IN statement question

    You simply take the first query and put it inside the parentheses in the second query.

    A CommandBuilder is not for generating SELECT statements. It is for generating DELETE, INSERT and UPDATE statements from SELECT statements.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] SQL IN statement question

    I had no idea you could do that in SQL statements.

    Thanks,
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width