Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select query

Author  Topic 

gagani
Posting Yak Master

112 Posts

Posted - 2012-07-03 : 05:55:03
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

22864 Posts

Posted - 2012-07-03 : 07:12:09
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
Posting Yak Master

112 Posts

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-07-11 : 06:40:39
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

52326 Posts

Posted - 2012-07-11 : 10:29:23
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
   

- Advertisement -