Hello,
I am tyring to combine several rows based on matching information..Fo r example i have the following table.
IOSC: FEATURE:
00029 LH
00029 SWFTERM
00029 WATS
00031 1PTY
00031 BUS
00031 FR
00031 LS
00031 SWFBOTH
00031 TC
00573 FAXTHRU
00963 1PTY
00963 BUS
00963 FR
00963 LS
00963 SWFBOTH
00963 TC
What I want it to display is
IOSC: FEATURE:
00029 LH,SWFTERM,WATS
00031 PTY, BUS, FR, LS, SWFBOTH, TC
00573 FAXTHRU
00093 1PTY, BUS, FR, LS, SWFBOTH, TC
Can anyone think of a query that can be used to get the desired results?
Thank you.
21 31873 NeoPa 32,569
Recognized Expert Moderator MVP
The only way that I can think of is not strictly within SQL.
You'd need a function that saved what it had been passed by previous records (until change in IOSC) and returned the concatenated list so far.
The results of a SELECT query based on that would then have to be grouped and the Max() value of the returned string would be what you require.
Did I mention it was very kludgy?
I am not too savvy with VB..Any suggestions?
NeoPa 32,569
Recognized Expert Moderator MVP
Paste this function into a module then run a query with the SQL below. - 'Concat returns a list of the Features
-
'so far found for the current IOSC.
-
Public Function Concat(strIOSC As String, _
-
strFeature As String) As String
-
Static strLastIOSC As String
-
Static strFeatures As String
-
-
If strIOSC = strLastIOSC Then
-
strFeatures = strFeatures & ", " & strFeature
-
Else
-
strLastIOSC = strIOSC
-
strFeatures = strFeature
-
End If
-
Concat = strFeatures
-
End Function
- SELECT IOSC,
-
Max(Concat(IOSC, Feature)) AS Features
-
FROM [YourTable]
-
GROUP BY IOSC
That worked perfectly! thank you so much!
NeoPa 32,569
Recognized Expert Moderator MVP
An alternative answer which better displays the flexible nature of this code, is included below. Notice this doesn't affect the calling code (SQL) at all.
Paste this function into a module then run a query with the SQL below. - 'Concat Returns lists of items which are within a grouped field
-
Public Function Concat(strGroup As String, _
-
strItem As String) As String
-
Static strLastGroup As String
-
Static strItems As String
-
-
If strGroup = strLastGroup Then
-
strItems = strItems & ", " & strItem
-
Else
-
strLastGroup = strGroup
-
strItems = strItem
-
End If
-
Concat = strItems
-
End Function
- SELECT IOSC,
-
Max(Concat(IOSC, Feature)) AS Features
-
FROM [YourTable]
-
GROUP BY IOSC
NeoPa 32,569
Recognized Expert Moderator MVP
Sometimes the GROUP BY clause is more complicated and contains more than one field. In this case the SQL format should be : - SELECT [GroupBy1],
-
[GroupBy2],
-
...,
-
[GroupByN],
-
Max(Concat([GroupBy1] &
-
[GroupBy2] &
-
... &
-
[GroupByN], Item)) AS Items
-
FROM [YourTable]
-
GROUP BY [GroupBy1],
-
[GroupBy2],
-
...,
-
[GroupByN]
I've been having the same problem folks. The function and SQL call looks like a good route to me but why do I keep getting "Data type mismatch in criteria expression"? Both the fields I'm trying to process are text fields, I'm a bit stumped as to what the problem is!
NeoPa 32,569
Recognized Expert Moderator MVP
I suggest you post your problem, clearly explained (with any relevant information) as a new thread. There's not enough information here to proceed on, and I doubt it would be helpful to discuss your problem in this thread.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jt |
last post by:
Is there a way to create a view that combines all rows from 2 tables
that have the same columns/fields?
thanks,
Judi
|
by: Ilan |
last post by:
Hi all
I need to add data from two Excel sheets (both on the same workbook)
to an existing table in my SQL DB.
The problem is that each sheet holds different fields for the same
record, though the records are sorted by row numbers.
(I had to split the fields to different sheets because Excel has a
limit of 256 fields in each sheet)
My sheets are quite large (~55,000 rows and 200 columns each) and I'll
have to repeat this action many...
|
by: Tome73 |
last post by:
How can I easily add the rows of DataTable1 to the rows of DataTable2. Both
queries are from the same table. I can always use the column names with
myRow, but I was wishing for a shortcut. When I try this it doesn’t
work.
for (int i = 0; i < dataTable1.Rows.Count; i++)
{
myRow = dataTable2.NewRow();
myRow = dataTable1.Rows;
dataTable2.Rows.Add(myRow);
|
by: rAinDeEr |
last post by:
Consider the following table (Single level of hierarchy ... No need for
recursion)
PRIMARY_COLUMN SECONDARY_COLUMN
-----------------------------
-----------------------------------
PARENT -
CHILD1 PARENT
CHILD2 PARENT
|
by: FuseICT |
last post by:
Hi,
for the purpose of this question i have 2 tables:
Table1 with fields ID, Name, NoteID
Table2 with fields NoteID, Note_Text
for every 1 record in Table1 there are many in Table2. If i use a standard JOIN i get multiple rows in a recordset but what i want is 1 Row with the field "Notes" that would comtain all the Note_text entries for the record in Table1.
example:
ID, Name, Notes
| |
by: Ken Fine |
last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets
and DataTables should be able to answer fairly easily. The basic question is
how I can efficiently match data from one dataset to data in a second
dataset, using a common key. I will first describe the problem in words and
then I will show my code, which has most of the solution done already.
I have built an ASP.NET that queries an Index Server and returns a...
|
by: dlee360 |
last post by:
Hello!
So I've been trying to figure out how to do the following in T-SQL:
Orig Table:
Col1 Col2 Col3
Set A Null Null 20
Set A Null 20 Null
Set A 10 Null ...
|
by: xMetalDetectorx |
last post by:
Consider these tables
Product
productID
styleNumber
description
Tag
tagID
tag
|
by: theberst |
last post by:
I've implemented this solution and found that it only works if the records with the same "CompanyName" are beside each other in the table. More specifically, the VBA code processes each record based on the order of primary key in the table. Is there a way to accomplish the goal of the original poster if records aren't adjacent in the table?
Thank you for your help!
|
by: Jeremy Goodman |
last post by:
Access 2007; Merging records containing multivalue drop down lists.
I have a database showing legislation information divided by State/territory. The database needs to be able to show the info from each legislation and then an overall picture for the state. There is no problem with merging some of the info using the steps in:
http://bytes.com/topic/access/answers/589999-combining-multiple-rows-one-field-into-one-result
The problem is...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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
| |