SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gagani
Yak Posting Veteran

94 Posts

Posted - 07/03/2012 :  05:55:03  Show Profile  Reply with Quote
ORDERID REFNO NAME
826190 367472 DARREN LEAROYD
826190 367473 DOUGLAS MCLAUGHLIN
826187 367467 LEE TOMKINS
826187 367468 JAMES NEIL JARDINE
826173 367452 PIETER BENJAMIN CLOETE
826173 367453 ANDREW ERIC JENKINS
826171 367450 JACK SAUNDERS-MILLS
826171 367449 STEPHEN JOHN COLLISTER

But I want the query to get the output in the following format:
orderid name1 name2
826190 DARREN LEAROYD DOUGLAS MCLAUGHLIN
826187 LEE TOMKINS JAMES NEIL JARDINE
826173 PIETER BENJAMIN CLOETE ANDREW ERIC JENKINS
826171 STEPHEN JOHN COLLISTER JACK SAUNDERS-MILLS

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 07/03/2012 :  07:12:09  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Refer this
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

gagani
Yak Posting Veteran

94 Posts

Posted - 07/03/2012 :  09:48:30  Show Profile  Reply with Quote
I am using sql 2000, is there anyway to solve with a query in it?
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 07/11/2012 :  06:40:39  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Create a function using this http://blog.sqlauthority.com/2008/06/04/sql-server-create-a-comma-delimited-list-using-select-clause-from-table-column/ and call that function in your SELECT statement. or try Quirky update http://beyondrelational.com/modules/2/blogs/70/posts/10865/quirky-update-in-sql-server.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 07/11/2012 :  10:29:23  Show Profile  Reply with Quote
are you sure you'll have only 2 names against each orderid? what if there are more than two? still you want only two names in output?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000