Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

SQL Statement In to SQL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Baffled - 12 Mar 2008 17:58 GMT
Hi All,

How would I convert the SQL IN statement to LinQ

Select *
from TableName
where FieldName in (Value1, Value2)

or

Select *
from Table1
where Field1 in (Select Field1 from Table2)

Thanks
Jon Skeet [C# MVP] - 12 Mar 2008 18:04 GMT
> How would I convert the SQL IN statement to LinQ
>
[quoted text clipped - 7 lines]
> from Table1
> where Field1 in (Select Field1 from Table2)

Try the Contains() operator. I haven't tried it for the latter type of
subquery, but I've seen it work for the first type where you pass in
the values.

Just remember that it's the other way round, so:

set.Contains(value)   ~=   value in set

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Alberto Poblacion - 12 Mar 2008 22:11 GMT
> How would I convert the SQL IN statement to LinQ
>
[quoted text clipped - 7 lines]
> from Table1
> where Field1 in (Select Field1 from Table2)

   As to the second one, it can be refactored into a Join:

Select Table1.* from Table1 Join Table2 on Table1.Field1=Table2.Field1

  This can then be readily converted into a LINQ query with a Join.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.