Solved

How to create a temporary table from resultset.

Posted on 2013-12-28
6
221 Views
Last Modified: 2014-01-20
When i run this query i get the following resultset

SELECT distinct SubjectCode from  IND13I.DBO.MSTMASSSTUDENTS
WHERE Course='B.Arch' and semester=1 order by 1

Resultset
SubjectCode
AR101
AR102
AR103
AR104
AR105
AR106
AR107

How to display this in horizontal or as columns  or how to transpose it so that i can create the table as
create table x (AR101 VARCHAR(200),AR102 VARCHAR(200) and so on

Is it possible.
0
Comment
Question by:searchsanjaysharma
6 Comments
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39744136
Yes, it is possible what you are looking for is called dynamic pivot functioanlity there are many examples out there in the web, I suggest you to look into one
0
 

Author Comment

by:searchsanjaysharma
ID: 39745519
Can you send any link.
0
 
LVL 15

Assisted Solution

by:Aaron Shilo
Aaron Shilo earned 250 total points
ID: 39746837
hi

this is a great example for using pivot to solve your problem

Pivot/Unpivot
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39746903
ashilo,

I suspect the keyword here was "dynamic"  :)
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 39746930
searchsanjaysharma,

Can you send any link.
See if this link helps:
http://bit.ly/1cigO7I

Blind links are no longer supported on EE, so you may want to hurry up and click on it before EE removes it.
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 39794094
tx
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question