473,666 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem is forming Query

Hello,

I have a table
say SalesLeads. This table is accessed through various front -ends and
it stores data for Sales leads of various products.

This table has a reference to another table(SalesLead RefTable)

Sample Data in SalesLeads

SalesLeadID Comments RefTableID
-------------------------------------------------------
1 Sample 1

Sample Data in SalesLeadRefTab le

ReferenceID TableName TableFieldName
-------------------------------------------------------
1 ProductTable ProductID
I need to form a query which will refer to the refdtableID and form a
dynamic query like

Select Comments , TableName.Table FieldName from SalesLeads,Tabl eName

Please let me know if this can be doen in 1 query
Jul 20 '05 #1
1 1117
You could implement a JOIN to one of many tables like this:

SELECT A.keycol, COALESCE(B.col1 , C.col1, D.col1) AS col1
FROM Something AS A
LEFT JOIN Table1 AS B
ON A.keycol = B.keycol AND A.entity = 1
LEFT JOIN Table2 AS C
ON A.keycol = C.keycol AND A.entity = 2
LEFT JOIN Table3 AS D
ON A.keycol = D.keycol AND A.entity = 3

Otherwise you would have to use Dynamic SQL inside an EXEC statement.

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2886
by: Andreas Schmitt | last post by:
Ok. I got the following problem. I created the following array and executed a function : CField* Spielfeld; CreatePlayField( Spielfeld ); ************************************************* ******** CreatePlayField looks like this ************ *************************************************
2
1786
by: DataB | last post by:
Hi everyone! I have a forms problem. Bakground: I have created a number of tables. Of these, I have a main parent table (Personal Details) and a number of other child tables (Tax file No., VISA card no.), etc...... All tables have a primary key of "Name", all child tables forming
17
5813
by: Yuri CHUANG | last post by:
Hi, I'm the beginner of the CPL.I write a program about the problem of Ring of Josephus,using DoubleLinkList data structure. I'm very confused that I think there is really no error in my code.But,the compiler sometimes show some strange errors,sometimes can pass through with an unknown trouble when it is running,and no result.So,could anyone give me some help? Thank you very much! Here is my code:...
3
1900
by: Samuel Burri | last post by:
Hi there I got a simple problem. As you can see in the posted source, I have two classes, where one is derived from the other. In fact, they also contain virtual functions. In the function doSomething of Derived I'd like to access private members of Base from the pointer I receive. The compiler (gcc 4.0) tells me, that Base::foo is protected and it can't access although Derived itself has access to the specified element. Probably its...
1
1326
by: mambenanje | last post by:
I am using the prototype ajax library but I realised that each time I am calling the server for xml the new records get appended to the old so when I display the xml data it shows the old ones and the new ones appended. for example when i do a search on questions by calling a php script the result will be displayed in a div area, when I make a new search, the new results will be appended and that is all messy can anyone help me out, I am...
6
2230
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description: this is a description Slot: slot2
5
3844
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ---------------------------------------------------------------------------------------------------------------------- | <a href="config.aspx?siteid=FIEJGIE">Site 1</a| Site 2 | <a href="config.aspx?siteid=DFOWEMF">Site 3</a>| In the example above site 2 is the "current" tab. I have the following code at the top of my...
11
1566
by: onkar.n.mahajan | last post by:
Is it possible to from function call on fly in C programming language ? I am faced with an interesting problem in that I need to take function name and arguments on fly (actually from Database as string ) and form a function call based on that ? something like FUN_NAME="fun1" , ARGS ="arg1,arg2,arg3" , for this pair function call must be
6
1412
by: ChipR | last post by:
I need a query to see who worked what hours on activities, and I have combo boxes to narrow the results to a specific activity or employee. I can't figure out how to get the sums of different types of hours into the same row. I had a query that went through every activity and did DSUMs for each category, but it was so slow and messy I had to trash it. I have a table EmployeeHours with fields PayPeriod - number EmployeeNumber - text...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.