Hi All, I hope someone is able to help me with this.
I am having a table with partnumber(s) like shown here (actually a access2003 database)
ID (autonumber, primary key)
Partnumber (text)
Replacment (text)
Description (text)
Comment (text)
..... <Some other fields>.
Data look like this:
ID Partnumber Replacement Description Comment
x 5030331-001 Partx
x 5030332-001 5030332-002 Part1 from vendor 1 Obsolete
x 5030332-002 8063737-001 Part1 from vendor 1 Obsolete
x 5030333-001 Partx
x .....
x 8063737-001 Part1 from vendor2
There are a lot of Partnumbers which are obsolete (this partnumber has a replacement part). I am searching for a query where (with one parameter, = partnumber to look for), where i can see complete relation. So if I am searching for partnumber 8063737-001 I get same result as when I am searching for 5030332-001 or 5030332-002.
Result should be like this:
ID Partnumber Replacment Description Comment ...........
x 5030332-001 5030332-002 Part1 from vendor 1 Obsolete
x 5030332-002 8063737-001 Part1 from vendor 1 Obsolete
x 8063737-001 Part1 from vendor2
has anyone any idea how to create this kind of query?
Ludo
1 2048
Hi,
I have made a table populated with some data based on what I have understood.
Then I am using a recursive CTE for fetching the result.
I am using SQL SERVER 2005+
Test the test table first and include the appropriate data over there and then run the query.
--Table creation and sample data population - declare @t table(
-
ID int identity
-
,Partnumber varchar(100)
-
,Replacment varchar(100)
-
,Description varchar(100)
-
,Comment varchar(100))
-
insert into @t
-
select '5030331-001','Part 1',null,null union all
-
select '5030332-001','5030332-002','Part1 from vendor 1','Obsolete' union all
-
select '5030332-002','8063737-001','Part1 from vendor 1','Obsolete' union all
-
select '5030333-001','Part 4',null,null union all
-
select '8063737-001',null,'Part1 from vendor 2',null
The output of the sample table is - ID Partnumber Replacment Description Comment
-
1 5030331-001 Part 1 NULL NULL
-
2 5030332-001 5030332-002 Part1 from vendor 1 Obsolete
-
3 5030332-002 8063737-001 Part1 from vendor 1 Obsolete
-
4 5030333-001 Part 4 NULL NULL
-
5 8063737-001 NULL Part1 from vendor 2 NULL
Based on the above table structure, here is the program - ;with cte as
-
(
-
select id,Partnumber,Replacment,Description,Comment
-
from @t
-
where Partnumber = '8063737-001' -- Enter the partnumber here
-
union all
-
select t.id,t.Partnumber,t.Replacment,t.Description,t.Comment
-
from @t t
-
inner join
-
cte c
-
on c.Partnumber = t.Replacment
-
)
-
-
select * from cte
-
order by id
-
option (maxrecursion 0)
And the output is: - id Partnumber Replacment Description Comment
-
2 5030332-001 5030332-002 Part1 from vendor 1 Obsolete
-
3 5030332-002 8063737-001 Part1 from vendor 1 Obsolete
-
5 8063737-001 NULL Part1 from vendor 2 NULL
Hope this helps.
Let me know in case of any concern
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Robert Marshall |
last post by:
Hi all,
Hoping someone can help me with an issue I'm having.
I'm using AccessXP to create a database of U.S. Census records. After
keying the data in, I decided to run a query to create a report for
each domocile address, and the three names that appear at each street
address for the three censii.
After running the query, the report...
|
by: deko |
last post by:
If I release a new version of my mbd (in mde format) and users want to
upgrade - how do they migrate their data?
For example, if the original was released as data1.mde and then I release
data2.mde (same table/data structures - just revised VBA code with perhaps a
new/updated form or two), what's the best way for users to get their data
into...
|
by: pw |
last post by:
Hi,
I am having a mental block trying to figure out how to code this.
Two tables:
"tblQuestions" (fields = quesnum, questype, question)
"tblAnswers" (fields = clientnum, quesnum, questype, answer)
They are related by quesnum and questype. There are records in
|
by: Apple |
last post by:
1. I want to create an autonumber, my requirement is : 2005/0001
(Year/autonumber), which year & autonumber no. both can auto run.
2. I had create a query by making relation to a table & query, but I
can't update record in query or in form. I believe the problem is due
to the source query.
In source query, there is a filter to show the...
|
by: Fendi Baba |
last post by:
I created a person table with various fields such as Suffix,
Salutation, etc, Some of these fields may not be mandatory for example
suffix. In the actual table itself, I only have a field for suffix ID
where 1=Phd, 2= MD. To display all of these to the user, I created a
form with an underlying query. The problem I am encountering is this,...
| |
by: themastertaylor |
last post by:
I've got a system to manage various quotes for building materials for
a number of sites. i want a query to produce a report that shows me
who HASN'T quoted for which sites. basically so i can print it off and
ring round and hurry them up a bit. I have my quote table which has
the supplier ID, Site ID and an ID for each quote.(I enter each...
|
by: wugon.net |
last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad
query performance
Env:
db2 LUW V8 + FP14
Problem :
We have history data from 2005/01/01 ~ 2007/05/xx in single big
table,
we try separate this big table into twelve tables and create a view
|
by: Miro |
last post by:
VS2008
I have created 3 tables.
Vendors
Customers
PhoneNumbers
each have their own key
Vendor has: VendorID - int unique identifier
Customer has: CustomerID - int unique identifier
|
by: LudoS |
last post by:
Hi All, I hope someone is able to help me with this.
I am having a table with partnumber(s) like shown here
ID (autonumber, primary key)
Partnumber (text)
Replacment (text)
Description (text)
Comment (text)
..... <Some other fields>.
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |