June 21, 2012 at 12:19 pm
Hi all,
So my data looks liek this
Name Item Numbers
a a 1
a b 2
a c 3
a d 4
a e 5
Is there a sql statement that could turn it into this?
Name A b c d e
a 1 2 3 4 5
Thanks,
Much appreciated
Alan
June 21, 2012 at 12:35 pm
Yes there is. Take a look at the cross tabs articles referenced in my signature.
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 21, 2012 at 1:19 pm
Is there a sql statement that could turn it into this?
Yes, look at PIVOT as well.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
June 21, 2012 at 2:41 pm
ScottPletcher (6/21/2012)
Is there a sql statement that could turn it into this?
Yes, look at PIVOT as well.
Check out the articles, they discuss pivot as well. 😛
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 21, 2012 at 4:41 pm
Thank you very much, it solved my problem.
June 21, 2012 at 5:16 pm
Is it possible to use this statement while importing data from excel at the "Write a query to specify the data to transfer" page? (before the table is created)
SELECT Reporting_Date, [Name],
SUM(CASE WHEN [Interaction Type] = 'A' THEN [Avg] ELSE NULL END) AS [A1],
FROM [dbo].[Interaction Detail]
GROUP BY Reporting_Date, [Name]
I keep getting this:
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).(System.Data)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply