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 |
|
ShaunBPD
Starting Member
5 Posts |
Posted - 2008-02-06 : 06:38:18
|
| Hi AllI have been having some problems get a select statement to work. I am trying to retrieve information from about five different tables and return into one result set, some of the results should return counts and some just general information. I have been struggling with this for days, I have finally decided to try and get some expert advice. I wouldnt be posting if I wasnt at my end of this one.Please let me know what information I need to post regarding table structures ect.Any help will be highly appreciated.Kind Regards |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-02-06 : 06:42:55
|
| yes, you need to post table structures and what output you want. Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
ShaunBPD
Starting Member
5 Posts |
Posted - 2008-02-06 : 07:33:47
|
| The application is a supplier evaluation application which uses question sets to evaluate suppliers and calculates weak, strong areas etc.One of the reports which I need to do is take from the categories and provide how many points where scored from the question table by putting them in subcategories.It is very complicated and I am really battling to get this right, it seems as though there is a common key between each table. But I can calculate scores etc and return them into a specific result set. I would also like to post a screen dump of how the report should look if possible.I have a categories table as follows:[ code]CREATE TABLE [dbo].[seCategories]( [CategoryID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [CategoryName] [nvarchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Description] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [MaxScores] [numeric](18, 0) NULL, CONSTRAINT [PK_seCategories] PRIMARY KEY CLUSTERED ( [CategoryID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY][ / code]I have a SubCategories table as follows:[ code]CREATE TABLE [dbo].[seSubCategories]( [SubCategoryID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [SubCatNumber] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [SubCatName] [nvarchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Description] [nvarchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CategoryID] [numeric](18, 0) NULL, [NumQuestions] [numeric](18, 0) NULL, [PercentageQuestions] [float] NULL, [MaxScore] [float] NULL, [DefaultPerform] [float] NULL, CONSTRAINT [PK_seSubCategories] PRIMARY KEY CLUSTERED ( [SubCategoryID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY][ / code]I have a questions table as follows:[ code]CREATE TABLE [dbo].[seQuestions]( [QuestionID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [Description] [nvarchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [QuestionType] [numeric](18, 0) NULL, [Number] [numeric](18, 0) NULL, [SubCatID] [numeric](18, 0) NULL, [QSet] [numeric](18, 0) NULL, [DepartmentID] [numeric](18, 0) NULL, CONSTRAINT [PK_seQuestions] PRIMARY KEY CLUSTERED ( [QuestionID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY][ / code]I have a Evaluation Detail table as follows:[ code]CREATE TABLE [dbo].[seEvaluationDetail]( [EvalDetailID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [ProcessID] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [QuestionID] [numeric](18, 0) NULL, [Score] [float] NULL, [AssesmentValue] [float] NULL, [EvalGroup] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, CONSTRAINT [PK_seEvaluationDetail] PRIMARY KEY CLUSTERED ( [EvalDetailID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY][ / code] |
 |
|
|
ShaunBPD
Starting Member
5 Posts |
Posted - 2008-02-06 : 07:36:09
|
My appologies, I am pretty new to this......Trying again with the proper The application is a supplier evaluation application which uses question sets to evaluate suppliers and calculates weak, strong areas etc.One of the reports which I need to do is take from the categories and provide how many points where scored from the question table by putting them in subcategories.It is very complicated and I am really battling to get this right, it seems as though there is a common key between each table. But I can calculate scores etc and return them into a specific result set. I would also like to post a screen dump of how the report should look if possible.I have a categories table as follows:CREATE TABLE [dbo].[seCategories]( [CategoryID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [CategoryName] [nvarchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Description] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [MaxScores] [numeric](18, 0) NULL, CONSTRAINT [PK_seCategories] PRIMARY KEY CLUSTERED ( [CategoryID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY] I have a SubCategories table as follows:CREATE TABLE [dbo].[seSubCategories]( [SubCategoryID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [SubCatNumber] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [SubCatName] [nvarchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Description] [nvarchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CategoryID] [numeric](18, 0) NULL, [NumQuestions] [numeric](18, 0) NULL, [PercentageQuestions] [float] NULL, [MaxScore] [float] NULL, [DefaultPerform] [float] NULL, CONSTRAINT [PK_seSubCategories] PRIMARY KEY CLUSTERED ( [SubCategoryID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY] I have a questions table as follows:CREATE TABLE [dbo].[seQuestions]( [QuestionID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [Description] [nvarchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [QuestionType] [numeric](18, 0) NULL, [Number] [numeric](18, 0) NULL, [SubCatID] [numeric](18, 0) NULL, [QSet] [numeric](18, 0) NULL, [DepartmentID] [numeric](18, 0) NULL, CONSTRAINT [PK_seQuestions] PRIMARY KEY CLUSTERED ( [QuestionID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY] I have a Evaluation Detail table as follows:[code]CREATE TABLE [dbo].[seEvaluationDetail]( [EvalDetailID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [ProcessID] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [QuestionID] [numeric](18, 0) NULL, [Score] [float] NULL, [AssesmentValue] [float] NULL, [EvalGroup] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, CONSTRAINT [PK_seEvaluationDetail] PRIMARY KEY CLUSTERED ( [EvalDetailID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-06 : 08:42:46
|
| What is your expected o/p? |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-02-06 : 08:46:01
|
| Can you give us some sample data and expected results? |
 |
|
|
ShaunBPD
Starting Member
5 Posts |
Posted - 2008-02-06 : 14:21:25
|
| I have a screen shot of the data and how it should look in the report at the end, is there somewhere I can post it or send it through to you guys? |
 |
|
|
ShaunBPD
Starting Member
5 Posts |
Posted - 2008-02-26 : 15:27:34
|
| Hi There, I was wondering if any one will still be able to assist in this matter.I have included how far I am now, I seem to be able to get the correct total of questions, but as soon as I add the seQuestionType table, I seem to get incorrect data from the first two tables. If needed, could someone tell me how to go about exporting the data which will be neededSELECT seSubCategories.SubCatName, COUNT(seQuestionTypes.QuestionType) AS QCount, SUM(seQuestionTypes.ValueScore) AS MaxScore, SUM(DISTINCT seEvaluationDetail.Score) AS ScoreFROM seSubCategories INNER JOIN seQuestions ON seSubCategories.SubCategoryID = seQuestions.SubCatID INNER JOIN seQuestionTypes ON seQuestions.QuestionType = seQuestionTypes.QuestionType INNER JOIN seEvaluationDetail ON seQuestions.QuestionID = seEvaluationDetail.QuestionIDGROUP BY seSubCategories.SubCatName |
 |
|
|
|
|
|
|
|