Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server Newbies
»
Translate rows in columns
Translate rows in columns
Rate Topic
Display Mode
Topic Options
Author
Message
tudorn
tudorn
Posted Monday, October 08, 2012 12:35 PM
Forum Newbie
Group: General Forum Members
Last Login: Monday, January 07, 2013 6:12 AM
Points: 4,
Visits: 18
Hello,
I have the following TitleDetailsRequest table: see TitleDetailsRequest.jpg attachment.
I need to get an output of the EN_No and FR_No for all the Stores and for all the titles Title based on the latest RequestDate as follow: see TitleDetailsRequest_Output.jpg attachment.
The Title table have all the titles that need to be in the output, so if a title is not in the TitleDetailsRequest table (i.e. Title3) the output should just display "0". Currently there are 30 titles in the Title table but the users can add new titles so hardcoding the titles into columns will not be an option considering that the users can also add new titles.
Your help with regards to this matter will be greatly appreciated.
Thanks
Post Attachments
TitleDetailsRequest.JPG
(
22 views,
20.71 KB
)
TitleDetailsRequest_Output.JPG
(
23 views,
18.91 KB
)
Post #1369996
Sean Lange
Sean Lange
Posted Monday, October 08, 2012 2:19 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:12 PM
Points: 8,619,
Visits: 8,260
Hi and welcome to SSC. What you have posted as desired output looks more like a report then the results of query. You have column group headers and column names. This type of thing is called a cross tab. It is generally more efficient (and far easier) to do this in the front end. This is very challenging to do in sql especially given the dynamic nature of what you are after. It can be done but it will take some considerable effort on your part.
There are two links in my signature about cross tabs. They will explain in great detail how to do this sort of thing.
If you are simply stumped after trying the methods laid out in there you should read the first link in my signature about best practices when posting questions. At that point you will need to post ddl (create table scripts), sample data (insert statements) and desired output based on your sample data.
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1370037
tudorn
tudorn
Posted Sunday, January 06, 2013 12:49 AM
Forum Newbie
Group: General Forum Members
Last Login: Monday, January 07, 2013 6:12 AM
Points: 4,
Visits: 18
Hi Sean,
Sorry I did not replied to you earlier.
The two posts/links that you recommended were very good and helped me a lot to create the reports I needed.
Thank you very much.
Post #1403311
Jeff Moden
Jeff Moden
Posted Sunday, January 06, 2013 11:30 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 32,906,
Visits: 26,793
I have to say that's one of the longer belated thank-you's I've seen in a while and I still think it's very cool that you came back to do so. Well done. Proof positive the later really is usually better than never.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1403419
Sean Lange
Sean Lange
Posted Monday, January 07, 2013 7:46 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:12 PM
Points: 8,619,
Visits: 8,260
tudorn (1/6/2013)
Hi Sean,
Sorry I did not replied to you earlier.
The two posts/links that you recommended were very good and helped me a lot to create the reports I needed.
Thank you very much.
Glad you were able to get it fixed.
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1403614
Sean Lange
Sean Lange
Posted Monday, January 07, 2013 7:46 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:12 PM
Points: 8,619,
Visits: 8,260
Jeff Moden (1/6/2013)
I have to say that's one of the longer belated thank-you's I've seen in a while and I still think it's very cool that you came back to do so. Well done. Proof positive the later really is usually better than never.
+1
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1403615
vinu512
vinu512
Posted Thursday, January 24, 2013 2:01 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 20, 2013 12:37 AM
Points: 1,049,
Visits: 1,439
tudorn (1/6/2013)
Hi Sean,
Sorry I did not replied to you earlier.
The two posts/links that you recommended were very good and helped me a lot to create the reports I needed.
Thank you very much.
Hi tudorn,
Did you get it done exactly as it shows in the image that you uploaded???.....would like to see the code....would be of help to others as well...could you please post it?
Vinu Vijayan
For better and faster solutions please check...
"How to post data/code on a forum to get the best help" - Jeff Moden
Post #1410990
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.