General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 30th, 2006, 02:14 AM
ZarrinPour ZarrinPour is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 2 ZarrinPour User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 55 sec
Reputation Power: 0
Excuse me for Double posting,But..Building Join Script For a Given Query Dynamically?

Hi

Apparently in this forum we can't Edit our Prevoius Post.So please Excuse me for posting this question Again. But This Time i've Tried to Describe my problem more clear.I hope you help me.

i'm developing a VISUALL query builder as the same as EnterPrise manager for making Sql Server Query.I'm simulating it exactly.so my application has followings Panes:

Diagram Pane
Grid Pane
Sql Pane
Result Pane

User can drop any tables in the Diagram pane and then select fields and make relations(joins) as he/she wants for example suppose user drops Customers and Orders Tables from NorthWind Database in the diagram pane and make a join from
Customers.CustomerID to Orders.CustomerID After that Sql Server in the Sql PAne will write the followings script:

SELECT *
FROM Customers INNER JOIN
Orders ON Customers.CustomerID = Orders.CustomerID

This is a simple join and my app is able to generate script for this query. Also in the background as you might have guessed i use a object structure for saving informaton about all the joins that user has made for example for the above query i create a Join Object and fill it with this info:

Left Table Name : Customers
Left Field Name : CustomerID

Right Table Name : Orders
Right Field Name : CustomerID

Join Type : Inner join
Join Operator : =

For each join i will do this.So I have all information about Joins that user has made
Visually.

But until now this was a very simple Query with one join .Imagine we have the following query.It is a right query and it has not grammatical mistake and can be Executed
properly regardless of its logics.

SELECT *
FROM Orders INNER JOIN
Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN
Products ON Orders.OrderID = Products.ProductID AND
Orders.EmployeeID = Products.SupplierID AND
Customers.CompanyName = Products.ProductName

Now in my app i have this information:

Join 1:
Left Table Name : Customers
Left Field Name : CustomerID

Right Table Name : Orders
Right Field Name : CustomerID

Join Type : Inner join
Join Operator : =

Join 2:
Left Table Name : Products
Left Field Name : ProductName

Right Table Name : Customers
Right Field Name : CompanyName

Join Type : Inner join
Join Operator : =

Join 3:
Left Table Name : Products
Left Field Name : ProductID

Right Table Name : Orders
Right Field Name : OrderID

Join Type : Inner join
Join Operator : =

Join 4:
Left Table Name : Products
Left Field Name : SuplierID

Right Table Name : Orders
Right Field Name : EmployeeID

Join Type : Inner join
Join Operator : =

Now i'm looking for a instruction ,a way or an algorithm to attach above information to achieve following Join Script as mentioned sql Query.

FROM Orders INNER JOIN
Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN
Products ON Orders.OrderID = Products.ProductID AND
Orders.EmployeeID = Products.SupplierID AND
Customers.CompanyName = Products.ProductName

or in the other words a functon with this specification:

GetJoinScriptFor(List of Join objects as a Array Parameter) : String containing Join Script.

I think at this point you should figure out my problem, am i right?

I tried to follow the lead of EnterPrise manager But sometimes
i can't guess its method.i hope you help me.
Thanks for your patience to follow my problem.

Thanks in advance.
With Best Regards.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Excuse me for Double posting,But..Building Join Script For a Given Query Dynamically?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT