473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Make a Bunch of Rows from a Table Resemble a Column

Currently I'm using a UDF and a physical temp table to accomplish this
and I want to know if there's any way of doing it in a query or
subquery instead...

In TableA there are a bunch of rows:

InvitationID (PK) PartyID Partygoer
1 1 Jim
2 20 Bob
3 2 Frank
4 1 Robert
5 1 Pete

In TableB are rows:
PartyID (PK) PartyDate PartyName
1 1/1/2000 WildParty
2 1/1/2000 BoringParty

When a user runs a query to search for all parties on 1/1/2000 I want
the result to look like:

PartyID PartyDate PartyName Partygoer
1 1/1/2000 WildParty Jim, Robert, Pete
2 1/1/2000 BoringParty Frank
I'm hoping there's a solution to this.
Thanks,
lq

Nov 23 '05 #1
9 1251
Razvan
Thanks for that example. However, both the solutions outlined use a
temp table and a custom function, both of which I said I am already
using and trying to figure out a way without...

"Currently I'm using a UDF and a physical temp table to accomplish this

and I want to know if there's any way of doing it in a query or
subquery instead... "

lq

Nov 23 '05 #3
So you are one of the kids that missed the part about 1NF in your RDBMS
class in college. Google it.

This is a report and you do it in the front end. But you can look up
some kludges that do not use Standard SQL.

Nov 23 '05 #4
> But you can look up
some kludges that do not use Standard SQL.
Or you can hire a consultant that deals with pure standard SQL, roughly
speaking, somebody that will cost more, not give you an answer to your
business problem and is more interested in there own indulgence.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"--CELKO--" <jc*******@earthlink.net> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com... So you are one of the kids that missed the part about 1NF in your RDBMS
class in college. Google it.

This is a report and you do it in the front end. But you can look up
some kludges that do not use Standard SQL.

Nov 23 '05 #5
You could use a UDF and cursor, the UDF would be called on the SELECT clause
so all the up-front accessing would be efficient and just the resulting rows
would require the resulting slow UDF code.

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"laurenq uantrell" <la*************@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Currently I'm using a UDF and a physical temp table to accomplish this
and I want to know if there's any way of doing it in a query or
subquery instead...

In TableA there are a bunch of rows:

InvitationID (PK) PartyID Partygoer
1 1 Jim
2 20 Bob
3 2 Frank
4 1 Robert
5 1 Pete

In TableB are rows:
PartyID (PK) PartyDate PartyName
1 1/1/2000 WildParty
2 1/1/2000 BoringParty

When a user runs a query to search for all parties on 1/1/2000 I want
the result to look like:

PartyID PartyDate PartyName Partygoer
1 1/1/2000 WildParty Jim, Robert, Pete
2 1/1/2000 BoringParty Frank
I'm hoping there's a solution to this.
Thanks,
lq

Nov 23 '05 #6
> This is a report and you do it in the front end.

Why?
Doing it at the back end has some advatages too:
1. Less data is transferred via the network. Since data is sent in
packets, 100 bytes less can easily mean 1 packet instead of 2 - 100%
better performance. In some cases that's crucial.
2. When (I'm not saying IF, but WHEN) the front end is rewritten, this
functionality is still there.
If several different front ends access one and the same query, there is
no redundancy either

Nov 23 '05 #7
laurenq uantrell (la*************@hotmail.com) writes:
Currently I'm using a UDF and a physical temp table to accomplish this
and I want to know if there's any way of doing it in a query or
subquery instead...


On SQL 2000, not really. (Unless you want to rely on undefined behaviour.)

On SQL 2005, there is actually away. Here I include only a canned example
that I got from one of the SQL Server devs:

select CustomerID,
substring(OrdIdList, 1, datalength(OrdIdList)/2 - 1)
-- strip the last ',' from the list
from
Customers c cross apply
(select convert(nvarchar(30), OrderID) + ',' as [text()]
from Orders o
where o.CustomerID = c.CustomerID
order by o.OrderID
for xml path('')) as Dummy(OrdIdList)
go

It's quite appalling, and I still have not learn enough XQuery to
understand how this works - only that it works.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Nov 23 '05 #8
Tony,
I have a very workable solution that uses only a UDF (no cursor and no
temp table) and seems pretty efficient on a table with approx 100,000
rows. I'm just wondering if there''s a way to do it in TSQL.

Nov 23 '05 #9
Yeah, I caught that feature addition in 2005 but since the client here
is running SQL 2K I didn't bother trying to figure it out.
Thanks for the reply.
lq

Nov 23 '05 #10

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

Similar topics

157
by: Dennis | last post by:
Is there some way --using, say, DOM or javascript-- to detect the current pixel width and/or height of a relatively sized table or of one of its columns or rows. I'm going to be writing javascript...
4
by: Support | last post by:
Hi, I want to know if I have changed a few records in my database using update / insert / delete methods, how can i later know which rows have been changed or modified ? I know the...
6
by: Fan Ruo Xin | last post by:
I try to copy a table from production system (DB2 UDB EEE V7.2 + fixpak5) to the testing system (DB2 UDB V8.1 + fixpak4a). I moved the data from productions system by using the following steps:...
9
by: YONETANI Tomokazu | last post by:
Hi. You can use the following SQL to construct rows with column names on the fly, rather than from an existing table like sysibm.sysdummy1: SELECT * FROM TABLE ( VALUES (0, 1, 2), (3, 4, 5), (6,...
2
by: dschectman | last post by:
This appears to be a feature of IE JavaScript. I am running IE 6.0 with the latest patches from Microsoft. Are there any workarounds other than re-coding the source HTML to place all the...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
3
by: Gary | last post by:
I have a bunch of labels, and want to put in some container, which should be: 1. The number of labels for each column is fixed, say 16/row. And the number of currently displaying rows is fixed,...
6
by: Ian Boyd | last post by:
Every time during development we had to make table changes, we use Control Center. Most of the time, Control Center fails. If you try to "undo all", it doesn't, and you end up losing your identity...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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...

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.