Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2011, 08:01 AM
Authorized User
 
Join Date: Aug 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Red face Query for Cloumn field as Rows

Hi,

I want to display column values as rows... Can anyone give me sql query for this...

My table looks like this - :
SELECT pk_userId, user_name
FROM dbo.User_Table

2 emma
3 manoj
4 sneha
5 Ankita
6 enna


Now I want a query for this -


emma| manoj| sneha| Ankita| enna ==> thiese are column name
| | | |
 
Old August 19th, 2011, 09:26 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There really isn't any standard SQL to do this because it doesn't fit the set model of SQL tables.

This sounds to me like you have a problem with the way you are constructing your table. Why do you have columns for the users? You should have a table with columns like UserID & UserName, then a row for each user. Then getting the list of users becomes trivial:
Code:
SELECT * FROM user_table
__________________
-Peter
compiledthoughts.com
twitter/peterlanoie





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query on million of rows wkm1925 SQL Server 2000 6 October 23rd, 2006 09:30 AM
How to check whether query retuns some rows or not kumar_raj13 ASP.NET 1.0 and 1.1 Professional 1 March 13th, 2006 12:59 AM
Query That Return 0 Rows in Results nimrod_r BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 5th, 2005 02:14 AM
getting a query rows as columns raamts SQL Language 1 February 24th, 2005 04:06 AM
Storing complete table rows in a single field KenNeedham Oracle 2 January 22nd, 2004 01:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.