Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making 1 row out of 2

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

My boss gave me this undaunting task of trying to reduce this query to one row. This can be done by eliminating two of the columns and doing a group, but he needs to see that data, too. He just wants it in one row.

I've highlighted the two that need to be removed to return one row and then will have to be brought back in. I just haven't the foggiest idea how.

Code:
SELECT 
OrderID, 
DNIS, 
AdKey, 
PhoneNumber, 
[b][COLOR=red]--ProductGroup, [/color][/b]
ContactFirstName, 
ContactLastName, 
BillingAddress, 
Address2, 
City, 
StateOrProvince, 
PostalCode,
Code, 
CreditCardNumber, 
expdate--,
[b][COLOR=red]--itemtype [/color][/b]

from ##tempj1

group by
	OrderID, 
	DNIS, 
	AdKey, 
	PhoneNumber, 
	[b][COLOR=red]--ProductGroup, [/color][/b]
	ContactFirstName, 
	ContactLastName, 
	BillingAddress, 
	Address2, 
	City, 
	StateOrProvince, 
	PostalCode,
	Code, 
	CreditCardNumber, 
	expdate--,
	[b][COLOR=red]--itemtype [/color][/b]

Can this be done?


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
JF:

Can you explain further? I'm messing with @@RowCount right now.

Thanks,

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
If you have two rows worth of data, how will you make them one row? Do you mean to pivot the data?

Please give simplified (but representative) sample data and desired results.
 
ESquared:

OrderID ProductGroup
12345 Product1
12345 Product2

Into 1

OrderID ProductGroup1 ProductGroup2
12345 Product1 Product2

Kind of like that, but the total rows is always unknown.


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
If you want to know how to do that search for PIVOT. It's easier in SQL Server 2005 than SQL Server 2000.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top