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.
Author |
Topic |
shawnmolloy
Yak Posting Veteran
93 Posts |
Posted - 2010-06-27 : 00:52:04
|
Hello.I always have problems when it comes to grouping. I'm hoping you can help :)This Query returns the following data:TSQL:select quizid, quizname, categoryname from userscoreswhere len(categoryname) > 0RESULTS:QuizID QuizName CategoryName3031 Property & Casualty-Terms PROPERTY INSURANCE2876 Workers Comp, Crime, etc. CASUALTY INSURANCE3031 Uniform Policy Provisions DISABILITY INSURANCE3088 Disability Definitions DISABILITY INSURANCE3233 Types of Life Policies LIFE INSURANCE2983 Health Plans (ex. HSA, HRA) - Health Plans (ex. HSA, HRA) DISABILITY INSURANCESo there are 6 different quiz names, under 3 different categories. I'd like the return data set to look like this:DISABILITY INSURANCE (Category Name) - QuizName - QuizName - QuizNameCASUALTY INSURANCE - QuizName - QuizName - QuizNamePROPERTY INSURANCE - QuizName - QuizName - QuizNameDoes this make sense? I just want to group by the CATEGORYNAME, and then display the data grouped as such.Can i do this with SQL alone, or is there a front end component to doing this kind of grouping?I'm using ASP for this particular app btw.Thanks!- shawnBy the way, here is the table DDL:USE [SSS]GO/****** Object: Table [dbo].[UserScores] Script Date: 06/26/2010 21:52:06 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[UserScores]( [userid] [int] NOT NULL, [correct] [int] NOT NULL, [total] [int] NOT NULL, [percentage] [int] NOT NULL, [quizid] [int] NULL, [quizName] [varchar](350) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [subCategoryId] [int] NULL, [categoryName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY]GOSET ANSI_PADDING OFF |
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-27 : 05:13:34
|
SQL is not meant for formatting the data.Formatting of data should be done at the front end.Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
|
|
|
|