Joining Two Tables using Join class

Background: At the moment SQL queries are reading from SQL.XML file. I think this is not good practise / standard. 

I think it is possible to have a class with methods say 'Join' class. Method can take parameters such as (TableName, PK etc) and join two Tables and return the SQL statement dynamatically. To enhance further the functionality same method may be over ridden/overloaded with more number of parameters to join above 2 Tables (if possible).

I like to request for a code snippet or reference sites/urls.

your input is very much appreciated.

4/14/2009 5:49:16 PM 29906 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 39

 I believe what you're describing is already incapsulated into LINQ. I haven't used it myself, but did some initial reading on it and you may want to do it as well.

Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
4/14/2009 10:34:27 PM

 Thanks for your reply.

I am waiting for few more suggestions to choose the best approach.

4/17/2009 12:08:35 PM

Similar Artilces:

How do I use a stored procedure to join two sql tables and use the fields for a listview
I am trying to create a listview combining fields of two tables with a common record.  I have a stored procedure with one parameter (@loginID).  I want to use this paramater to look for a common record in two tables, and join the date of the fields of the two selected records.   I know this isn't right, but hopefully someone can modify it for me.Create PROCEDURE [dbo].[tblLoginSelectCommandWithParam] [ @LoginID integer ] AS Select * from tblLogins Select * from tblLoginDetail Join tblLoginDetail Where @LoginID = LoginID SELECT tblLogins.*, t...

How to join two tables with LINQ inner join in a class file?
Hello, I need a solution on how to INNER JOIN two tables with LINQ in a class file which I can utilize from an ObjectDataSource control. I want to do development in object oriented fashion. Currently I only know how to use LINQ to pull data from single tables such as in the example below: Imports SystemImports System.Collections.GenericImports System.LinqImports System.Data.Linq Partial Public Class Class1     Public Shared Function GetCategories() As IEnumerable(Of Category)        Dim dc As New DataClassesDataContext()  &nbs...

Join two table using a link table
I have a News table with news messages in it. I also have a Photo table with names of pictures in it. In a datagrid you are able to link both. But, it is possible that there are news messages that have NO photo linked others have a photo linked. These links are stored in a 3rd table: PhotoLink. This holds only the PhotoID and the NewsID that are linked. This also means that if no newsID is linked to any Photo the photolink table has no rows for it. SELECT DISTINCT News.NewsID, News.Content, Photolink.PhotoID, Photos.PhotoNameFROM News, PhotolinkRIGHT OUTER JOIN PhotoLink ON Photolink.News...

Join aspnet_User table with an employee table using LINQ to SQL?
Hi, I am new to ASP.NET and I'm writing an application that uses SQL Server express for it's data store. I'm using Linq to SQL to connect to my data layer. I'm also using the Membership API to manage users and roles in my application. I store additional user information in a table called "employee" which has a one-to-one relationship to the table aspnet_Users using UserId as a key (I enter the UserId created in the aspnet_Users table into the employee table). I'm trying to populate a gridview with my employee data but I also want it to display what roles the emp...

joining two tables in .NET??
Hello all, I have two datatables "customersReached " and "customersGuessed " and I want to combine them into one table only, the problem is that one table exeeded to the other by two fields, so what can I do??????? Mahmoudona what do you mean bu exeeded ? I mean exceeded, sorry  this is miss typing. I mean that a table has two columns more than the other. example table A has fields cat, dog, fish. table B has fields cat, dog, fish, bird, mouse.   thank you   You can use DataTable.Merge method DataTable.Merge (DataTable, Boolean, MissingS...

if i want to join two sql tables ...
do they have to have a common primary key? Not necessarily. You can get a CROSS JOIN of both tables but I am not sure how much help that would be. ***********************Dinakar NethiLife is short. Enjoy it.*********************** I have these two tables id int UncheckedCategoryID int CheckedListTitle nvarchar(50) CheckedBlurb nvarchar(250) CheckedFileName nvarchar(50) CheckedByLine nvarchar(50) CheckedHTMLCopy nvarchar(MAX) CheckedMainStory bit CheckedMainStoryImageFile nvarchar(50) CheckedPublish...

INNER JOIN: joining two different colums with one table?
Hello everyone, I'm stuck on something here. Any help would be great. This is a relational database question. I'm trying to inner join two columns of one table with one column of another. The follwoing code doesn't work, but I think you can see what I'm trying to do. Procedure _Links_List AS CREATE TABLE #TempTable ( LinkId int, LinkCategory varchar(50), LinkStatus varchar(50), LinkName varchar(50) ) INSERT INTO #TempTable ( LinkId, LinkCategory, LinkStatus, LinkName ) SELECT LinkId, _SubCategories.Su...

Join or not Join ?
What is better, why ? 1) Cursor table1 ........... exec sp_get_balance /* Get balance from table2 */ /* Use balance */ .......... Close Cursor 2) Cursor from table1,table2 /* Get balance directly in the join */ ............ /* Use balance */ ............. Close Cursor Asume table1 and table2 are very big and the search of balance in table2 has a index support Thanks, R Garces Well, a lot of assumptions would have to be put in place here, but from an efficiency point of view, the join is the best approach. There is ...

How do I join two tables in SQL Server?
I have been reviewing the video series at this site and have found them very helpful but have a need... I have two data tables one of which is quite large and another table that is small. They have at least one exact field in common, lets call it room number. How do I recognize both tables (in different databases) and join them so I can search a unique item in one table and select its associated data in the other table? I don't image there is a video on this topic for this VB.NET student? you can just use Fully Qualified Names (four part names) in your sql statements.  As long as...

i cant use more than two table with inner join

How to use left outer join in two tables?
Hi all, I need a small help in creating a join query in sql. My two tables are A and B. A has got columns id, dname, counter and date. B has got two columns link and date. The primary key of A is the column Id whereas in table B, both are primary keys(composite key). I need to get the records (id,dname,counter) from A which has no corresponding link in table B. To be precise, If the table A has fields (id,dname,counter) (1,abc,2000) and if table B has no record for abc, this row should be returned from A.I hope using left outer join will help me in getting my desired result...

How to join two Linq.tables using Some Where Clause
 How to join two Linq.tables using Some Where Clause. As i am using this code for the two tables.:   var SearchUser = (from u in db.Users join l in db.LoggedInUsers on u.UserID equals l.UserID into joined                              select u.Username= joined.Contains(User)); Hi banu_pushpa, What you showed us is a left outer join. While if you use Where clause in LINQ query, it'll be an inner join. For instance: va...

DataWindow using join SQL using PB 11 with MS SQL 2005 is slow
Sir: My PB Applications were migrated from PB 6.5 (or PB 9) to PowerBuilder 11.2. Database is MS SQL 2005. I have some datawindows using join(innor or outer) SQLs.When the application version is PB 6.5(or PB9), datawindow's performance is fast.When the application version is PB 11.2,the performance is slow. I change my connection driver by using SNC、OLE DB and ODBC,the performance is still slow. So,is this PB problem? Or any other problems?How should I solve this problem? Thanks a lot! Barkely ...

Deleting rows from two tables using join query
Help me to solve this.... ThanksA.RaMeShSuNdAr  DELETE TABLEA From TABLEB WHERE TABLEA.ID = TABLEB.TID Imran[MCTS]Few have audacity to speak truth delete from table1 as c join table2 as p on = p.idHappy coding...

Web resources about - Joining Two Tables using Join class -

Neighbor joining - Wikipedia, the free encyclopedia
... species or sequences) to form the tree. Starting with a star tree (A), the Q matrix is calculated and used to choose a pair of nodes for joining, ...

Votizen and Causes are joining forces! - Facebook
Votizen hat eine Notiz mit dem Titel Votizen and Causes are joining forces! geschrieben. Du kannst den vollständigen Text hier lesen.

Interview: Veteran Product Lead Josh Elman on LinkedIn, Facebook, Twitter — and Joining Greylock
Josh Elman has been in the trenches of product development since mid-1990s, with his resume reading like a who’s who of major web companies today. ...

SnappyTV is joining the flock
One of the best ways to follow events as they unfold is through real-time videos on Twitter. As we continue to invest in video, it’s important ...

Joining Hands 2 for iPhone, iPod touch, and iPad on the iTunes App Store
Get Joining Hands 2 on the App Store. See screenshots and ratings, and read customer reviews.

Multiple Page Wizard for Joining Delicious - Flickr - Photo Sharing!
Sequence Map - Sequence map at the top of the page lets the user know where he is in the process - Current step is highlighted. - Completed steps ...

Daniel Bryan reveals his true motives for joining the Wyatt family: Raw, Jan. 20, 2014 - YouTube
Daniel Bryan had a plan the whole time.

Pakistan debates joining the Saudi-led coalition in Yemen
Joining the war would mean supporting longtime ally, Saudi Arabia, but also threaten relations with neighbouring Iran, reports Tom Hussain

Burger King proposes joining forces with McDonald’s to create fusion burger for Peace Day
It’s the fast-food gourmand’s ultimate fantasy – a burger featuring some of the best features of Burger King and McDonald’s ...

Ex-Labor head Matthew Gardiner 'defriended' Facebook friends before 'joining Kurdish fighters in Syria' ...
An Australian politician under investigation for joining the civil war in Syria claims to have 10 years experience in the army and left behind ...

Resources last updated: 12/17/2015 4:34:06 AM