Group Data For Survey

Feb 5, 2008

hi,

i'm having following data:


create table survey
(
clientID int not null,
questionID int not null,
Answer int not null
)

insert into survey (clientID, questionID, Answer) values (1, 1, 1)
insert into survey (clientID, questionID, Answer) values (1, 1, 2)
insert into survey (clientID, questionID, Answer) values (1, 1, 4)
insert into survey (clientID, questionID, Answer) values (1, 1, 5)
insert into survey (clientID, questionID, Answer) values (2, 1, 1)
insert into survey (clientID, questionID, Answer) values (2, 1, 5)
insert into survey (clientID, questionID, Answer) values (2, 1, 8)
insert into survey (clientID, questionID, Answer) values (3, 1, 2)
insert into survey (clientID, questionID, Answer) values (3, 1, 4)
insert into survey (clientID, questionID, Answer) values (3, 1, 6)
insert into survey (clientID, questionID, Answer) values (3, 1, 9)
insert into survey (clientID, questionID, Answer) values (4, 1, 8)
insert into survey (clientID, questionID, Answer) values (5, 1, 1)
insert into survey (clientID, questionID, Answer) values (5, 1, 5)
insert into survey (clientID, questionID, Answer) values (5, 1, 9)


and i want to get it out like this:

ClientIDQ1_1Q1_2Q1_3Q1_4
----------------------------------------
1|1|2|4|5|
2|1|5|8|0|
3|2|4|6|9|
4|8|0|0|0|
5|1|5|9|0|

but i get the following output:

clientID Q1_1 Q1_2 Q1_3 Q1_4
----------- ----------- ----------- ----------- -----------
1 12 12 12 12
2 14 14 14 14
3 21 21 21 21
4 8 8 8 8
5 15 15 15 15

(5 row(s) affected)

with this code:



SELECT

distinct(clientID)
,Q1_1
,Q1_2
,Q1_3
,Q1_4


from
(select
distinct(clientID)
,sum(case when QuestionID = 1 and Answer in (1,2,3,4,5,6,7,8,9,10) then Answer else 0 end) as Q1_1
,sum(case when QuestionID = 1 and Answer in (1,2,3,4,5,6,7,8,9,10) then Answer else 0 end) as Q1_2
,sum(case when QuestionID = 1 and Answer in (1,2,3,4,5,6,7,8,9,10) then Answer else 0 end) as Q1_3
,sum(case when QuestionID = 1 and Answer in (1,2,3,4,5,6,7,8,9,10) then Answer else 0 end) as Q1_4


from
dbo.survey

group by clientid) as x

group by
x.clientID
,x.Q1_1
,x.Q1_2
,x.Q1_3
,x.Q1_4


order by clientID asc


what am i doing wrong? Thank you

View 9 Replies


ADVERTISEMENT

SQL Server ETL Survey: Take The Survey For A Chance To Win A 80GB Zune!

Nov 27, 2007

SQL Server Integration Services team would like to hear from you. Our goal is to understand your current Data Extract, Transform & Load (ETL) practices and prioritize features for future releases.

You will have a chance to win one of five 80GB Zunes. To win a Zune, you must fill out the survey by Dec. 20, 2007.

To participate in the survey, please click here: https://mscuillume.smdisp.net/Collector/Survey.ashx?Name=SqlETLSurvey2


Thank you,
SSIS Team

View 2 Replies View Related

Using Nvarchar(max) For All Data Types In A Survey System

Apr 23, 2008

I am working on a survey system with another DB Engineer.Our current design includes 1 table per Question Type (Numeric, Boolean, Text), Response values are tightly coupled based on data being entered, to keep things simple assume there are only 6 tables in this this system (1 for each Question Type to define the "rules" of the data entered, and 1 for each Response collection).He is a former .Net programmer and has been talking with the .Net guys on the project and he is proposing that we abstract our Question Types to use one table and store the Input Values all as nvarchar(max).This obviously simplifies the DB design and reduces the amount of work I will need to do so I should be all for it. I guess I am a little concerned that we are no longer tightly coupling the data types and essentially leaving all the validation up to the application. Also should I be worried that a bunch of bit data will be stored as 1/0 in an nvarchar(max) column?Thanks,-John

View 13 Replies View Related

Survey DB Schema

Dec 12, 2004

I am trying to modify a survey DB schema created by OOP(Object Oriented Programming) snobs who had their heads so far up their butts(in my opinion).
This is current schema created by them.

Diagram 1 (OOP snobs version)
http://us.f3.yahoofs.com/users/41a4fde6zcff655d9/a2ae/__sr_/2761.jpg?phsEJvBB3t1v7URD

Actually there aren't a several foreign keys as they are shown in the picture, but that's what they(OOP snobs) are doing to the table "Response". They are inserting question_collection_id and its name as well as question_id and its name to Response table. However, it was not ill-intended, "We just wanted to load the report quickly"(OOP snobs).
But I really recommend this schema, Because of its simplicity.

Diagram 2 (My version)
http://us.f3.yahoofs.com/users/41a4fde6zcff655d9/a2ae/__sr_/e890.jpg?phrEJvBBF0.lGY5Y

Yet I haven't proven that my schema will provide report just as quickly as OOP snobs' version. As mentioned earlier, since they don't have foreign key constraints accordingly, I do find quite number of discrepancy on values of "question" columns between "Question" and "Response" tables and "question_collection" columns between "question_collection" and "Response" table. I can provide schedule task to eliminate those problems. But I really prefer my schema than theirs. So far, I can explain mine is better just because of its simplicity and DBA's gut instinct. I'd like to hear Superior Expert's opinion which schema is better and why one is better than the other.

Attached is also zip files of schema images if you can't see them by those URL.

View 4 Replies View Related

Would You Like To Participate In The BI Survey?

Jun 16, 2007

The BI Survey is the largest independent survey of BI technology users worldwide. (It used to be known as the OLAP survey, but has expanded to cover a broader array of BI technologies.) The survey analyzes people's buying decisions, BI implementation cycles and business results achieved.



The BI Survey is strictly independent --- they ask vendors like us to ask our customers like you to participate, but we don't have any other involvement --- except closely reading the results, of course. The Survey will send all participants a summary of the full survey results and place them in a drawing for ten $50 Amazon vouchers.



You can complete the survey on-line by following these links:


English version - website: http://www.eu-survey.com/webprod/cgi-bin/askiaext.dll?Action=StartSurvey&T1=BI&lan=1&lin=20

German version: http://www.eu-survey.com/webprod/cgi-bin/askiaext.dll?Action=StartSurvey&T1=BI&lan=2&lin=67



Let your voice be heard!

View 2 Replies View Related

SQL Server DBA Salary Survey

Aug 29, 2006

I am going into salary negotiationyearly review next month after my week off and I am trying to determine what to ask for. I am thinking another 10K and an extra week off would not be unreasonable, but I wanted to get some idea of what you guys think I should ask for in terms of pay.I have been developing software for seven years and I have been a dba for a little over five. I live in pricey northern Virginia. On a fairly regular basis I do about 55 to 60 hour weeks. On my DBA team, I am the only one who can handle both development and production tasks. The others are strictly developers. Although I have been relieved of most of my customer support tasks by our newbie, the customer support manager still brings the nastier bits to me. It is my perception that the more complex tasks get assigned to me. I get told on a regular basis that I am the best dba this place has ever had and other embarrassing accolades are regularly thrown my way. After a year, other than my boss I am the dba that has been here the longest in high turnover high burnout company. This year as we try to move to a SAP model, it looks like we will be going to 24/7 support on a disaster recovery model I am designing and implementing, so I guess I am getting the pager.So how much money should I be asking for?you can PM me with a number if you want.

View 1 Replies View Related

Survey Statistic Query

Feb 5, 2007

Is there a possibility to express the text column with SELECT SQL command, to get AS column which will represent all values in the field?

I mean - to convert:


IDresult__IDquestion_answers
....
24______72_________178,180,191
25______77_________221,224
26______79_________291,298,301,302
27______84_________522,523,525
....


into:


IDresult__IDquestion_numberedanswers
....
24______72_________178
24______72_________180
24______72_________191
25______77_________221
25______77_________224
26______79_________291
26______79_________298
26______79_________301
26______79_________302
27______84_________522
27______84_________523
27______84_________525
....


Can SQL do that?

View 14 Replies View Related

Calculating Survey Scores

Oct 16, 2007

I have surveys that I need to add weights to and was wondering if there was a way to convert the contents of a column.

select empid, ans_for_ql,
(if ans_for_ql = A then 0, B then 3, C then 5) as weightscore,
ans_for_q2,
(if ans_for_q2 = A then 8, B then 4, C then 2, D then 1, E then 0) as weightscore

Here is what the table looks like:

empid | Ans_for_Q1 | Ans_for_Q2
1001 A C
1002 B E

And these are the possible answers and what they need to be converted to:

Weights for answers to Question1
Q1_A = 0
Q1_B = 3
Q1_C = 5

Weights for answers to Question2
Q2_A = 8
Q2_B = 4
Q2_C = 2
Q2_D = 1
Q2_E = 0

View 3 Replies View Related

Database Administration Survey

Jul 23, 2005

Hi,We are a systems research group at the Computer Science departmentatRutgers University, and are conducting a survey to understand detailsabout network, systems and database administration. We hope that thisinformation would help us recreate a realistic environment to helpresearch in 'systems management'.We request network, systems, and database administrators to take thissurvey. As an incentive, all surveys completed in their entirety willbeentered into a drawing of a number of $50 gift certificates (fromAmazon.com).We hope you have a few minutes to take the survey which is located at:http://vivo.cs.rutgers.edu/administration_survey.htmlResearch in our group:The goal of our research is to improve the overall availability andmaintainability of services. Since administrators form an integral partof these services, a key aspect of this work is to build environmentsand tools that ease the task of service administration. In particular,environments which would help administrators know how their actionsmight impact the real service (before performing them for real), webelieve would be useful in preventing inadvertent actions. This surveytries to understand the existing environments, what administrators docurrently to test the 'validity' of their actions, and the difficultiesthey face in doing so. The two specific systems we are looking at arenetworks and databases, as we believe these are important components ofmany services.If you have any questions regarding this survey or our work, feel freeto email us:Fabio Oliveira (fabiool at cs || rutgers || edu), orKiran Nagaraja (knagaraj at cs || rutgers || edu)Thanks for your time,Fabio OliveiraPhD student, Vivo Research Group (http://vivo.cs.rutgers.edu)Rutgers University

View 4 Replies View Related

International Motivation Survey

Jul 23, 2005

Dear Madam/Sir,You are invited to participate in an international research study. Thisresearch project is headed and led by Cambridge student Nico Baumgarten.What is it all about?It is a well-known fact that there exist many differences between cultures.However, how these differences effect motivation if there are effects atall is not yet clear. This survey is set out to change this. With yourhelp, it will be possible to achieve this.Therefore, we kindly ask you to spare only 10 minutes of your time andvisit the survey home page.Go to the survey http://crosscultural.research.yi.orgor if this does not work the direct link http://82.4.146.32Who participates?All over the world, people are chosen to participate in the survey.Although the survey is completely anonymous, each person is arepresentative of his/her country. Hence, it does not matter, which job aperson has, whether he/she is male or female, old or young. The more peoplechoose to participate the more accurate this survey is going to representand show cultural influences as well as similarities.So if you want to tell your friends about this survey - Please Do So! Justforward this email to your friends or use the feature on the survey homepage.What is in it for you?With your help your country will be represented in the survey.Of course, you can opt-in to receive the results of the study at the end ofthe survey.Any information you provide will be kept strictly confidential andanonymous.Thanking you in advance for you support I remain withKind regardsNico Baumgartenhttp://crosscultural.research.yi.orghttp://82.4.146.32

View 1 Replies View Related

Web Survey Database Design

Aug 26, 2005

I am a developer and I have a problem trying to design a system tomanage data coming from web surveys. Each section can potentially havedozens of questions, i.e., fields.I am focusing here only on the table(s) that will hold the survey data.I do not have any DDL as I am still trying to understand this!All the examples I have found so far in books and on the web seem todeal with fairly limited data, that is easily, or so it looks, brokendown in multiple tables.It seems that, from my research, having a wide table per survey sectionwith each field as a column, which has been suggested to me, is notproper design for many reasons - missing values for non-requiredquestions, table with 100s of possible columns, etc... - so I playedwith the idea of a single table where one of the columns would be theforeign key pointing to a questions table and another column would holdthe data (this is a simplified explanation.)The problem with this is that now this column will have to accomodateall types of data, from bits to large varchars, and that fieldvalidation seems now impossible jeopardizing data integrity.What do knowledgeable designers come up with in this case? Can someonepoint me in the right direction?Jerry

View 2 Replies View Related

DB Design Question - Survey System

Jul 23, 2005

I've written several survey systems in which the majority of the questionshave the same or similar responses (Yes/No, True/False, scale of 1 - 5,etc).But this latest survey system I'm working on has 8-10 sections, with avariety of question attributes and answer scales. Some items have just adescription and require a Yes/No answer, others have a description and anactive status and require a Yes/No and price answer, some require a comment,etc.Rather than build a separate response table for each survey section, I wasthinking of building one generic response table, and trying to force allsections to fit by adding columns - some of which won't apply to some items.Like this:Survey Category (will apply to all items)Survey Section (will apply to all items)Item Description (will apply to all items)Item YN (will apply to all items)Item Price (will apply to about 10% of the items)Item Points (will apply to about 10% of the items)Item Active YN (will apply to about 10% of the items)Item Fail YN (will apply to about 10% of the items)Item Comment (will apply to about 10% of the items)For instance, in the structure above the field "Item YN" would representmultiple types of answers: is the item in use?, is the item in place?, isthe item given away for free?, is the item on display?, etc. Basically,anywhere a Yes/No answer is used.The advantage is one source table (rather than 8) for storing answers, andit might be easier to query and report on.The disadvantages I see are 1) it's more difficult to understand the meaningof the responses when the answer field is named Item YN, and 2) you have anon-normalized table that's difficult for a 3rd party to understand.If I have the questions and responses in separate tables, I'll use nameslike "ItemComplimentaryYN" and "ItemUsedYN" depending on the question. It'seasier for others to learn the data.I actually don't like the "generic" approach, and probably won't use it, butI figured I'd try to get some input from others who've written surveysystems.Thanks

View 5 Replies View Related

Relational Database Usage Survey

Oct 15, 2005

Dear friendsI am conducting a survey on Relational Database usage and would likeyour help. The study is part of my MBA Dissertation.Could you kindly spare 5 minutes to take part in this survey?http://FreeOnlineSurveys.com/rendersurvey.asp?id=120816ThanksRajeev

View 11 Replies View Related

Design Responses Table In Survey Database

Mar 23, 2015

I have questions table and answers in survey database. Now I design responses table from users !

CREATE TABLE [dbo].[Response](
[ResponseId] [int] IDENTITY(1,1) NOT NULL,
[SurveyId] [int] NULL,
[QuestionId] [int] NULL,
[AnswerId] [int] NULL,
[VoterId] [int] NULL,

[Code] ...

My Questions : How can I store data if questions is multiply answers (checkbox type) ?What is best way ?

View 16 Replies View Related

Survey: Enterprise Architecture And Software Development

Aug 5, 2006

Several prominent researchers are conducting a survey and looking for500 respondents by Friday on the topic of enterprise architecture andsoftware development. Here is the link to the survey:http://www.surveymonkey.com/s.asp?u=845572436515After completing the survey, results are displayed immediately. A smalldonation will be made to a charitable organization after itscompletion.http://duckdown.blogspot.com/

View 3 Replies View Related

Design Question For Survey/questionnaire Type Application

Dec 20, 2007

I am a developer and I have a problem trying to design a system to
manage data coming from web surveys. On average each subject will take
part in more than one survey and each survey may potentially have 100+
questions.

I am focusing here only on the table(s) that will hold the survey
data.

I'm thinking about having a wide table storing each question in the
survey(s) as a column against the subjects. My main concerns with this
approach:

- the "yuckiness" and potentially other performance issues(?)
associated with a table with 100s of columns
- the 8kb size limit per row (unlikely to touch it, but possible)
- 1024 column limit (unlikely to touch it, but possible)

Another approach obviously is to have a single table where we have, in
a simplified version, 3 columns: person_id, question_id and data/
answer. The problem with this is that the "data" column will have to
accommodate
all types of data, from bits to varchars, and that field validation
seems now impossible jeopardizing data integrity, and most
importantly, you can't easily work with the data in filtering/
reporting etc.

What do knowledgeable designers come up with in this case? Can someone
point me in the right direction?

View 2 Replies View Related

Analysis :: Conditional Sum Based On Latest Survey Answer

Jul 24, 2015

Basically our cube contains two different Facts:

- Sales Volume: Information about sold articles to a customer incl. Selling date
- Survey: irregular answered survey questions about customers incl. date of answer
and three Dimensions:
- Customer
- Date
- Survey Answer: Information about possible Answer values (e.g. Yes / No)

Relations:
Fact: Sales Volume  ------>  Dim: Customer  <------  Fact: Survey   ------>  Dim: Survey Answer
                    '-------------->      Dim: Date       <----------------'

We would like to be able to determine the aggregated sales volume (sum) of a customer for a specific period depending on the latest survey answer within this period.

For example:
Selected Time period: Jan - Jul 2015
Sales Volume Customer X - Jan - Jul 2015: 1000 Litres
Sales Volume Customer Y - Jan - Jul 2015: 500 Litres

Surveys answered:

15th Jan 15: Customer X, Survey Question A: Yes
2nd Mar 15: Customer X, Survey Question A: No
20th Apr 15: Customer X, Survey Question A: Yes

10th Feb 15: Customer Y, Survey Question A: Yes
20th Jul 15: Customer Y, Survey Question A: No

Latest survey answer (Jan-Jul) Customer X, Question A: Yes
Latest survey answer (Jan-Jul) Customer Y, Question A: No

Excel Pivot should show something like this:

Question       |      Latest Answer:     Yes                |       No         |

------------------------------------------------------------------------------------
A                    |     1000 Litres     |    500 Litres    |

How this is possible and has to be implemented?

View 5 Replies View Related

Reporting Services :: Display Group Name Value Of Each Group In Column Header Outside The Group?

Sep 29, 2015

I have an SSRS 2012 table report with groups; each group is broken ie. one group for one page, and there are multiple groups in multiple pages.

'GroupName' column has multiple values - X,Y,Z,......

I need to group 'GroupName' with X,Y,Z,..... ie value X in page 1,value Y in page 2, value Z in page 3...

Now, I need to display another column (ABC) in this table report (outside the group column 'GroupName'); this outside column itself is another column header (not a group header) in the table (report) and it derives its name partly from the 'GroupName'  values:

Example:

Value X for GroupName in page 1 will mean, in page 1, column Name of ABC column must be ABC-X Value Y for GroupName in page 2 will mean, in page 2, column Name of ABC column must be ABC-Y Value Z for GroupName in page 3 will mean, in page 3, column Name of
ABC column must be ABC-Z

ie the column name of ABC (Clm ABC)  must be dynamic as per the GroupName values (X,Y,Z....)

Page1:

GroupName                 Clm ABC-X

X

Page2:

GroupName                 Clm ABC-Y

Y

Page3:

GroupName                 Clm ABC-Z

Z

I have been able to use First(ReportItems!GroupName.Value) in the Page Header to get GroupNames displayed in each page; I get X in page 1, Y in page 2, Z in page 3.....

However, when I use ReportItems (that refers to a group name) in the Report Body outside the group,

I get the following error:

Report item expressions can only refer to other report items within the same grouping scope or a containing grouping scope

I need to get the X, Y, Z ... in each page for the column ABC.

I have been able to use this - First(Fields!GroupName.Value); however, I get ABC-X, ABC-X, ABC-X in each of the pages for the ABC column, instead of ABC-X in page 1, ABC-Y in page 2, ABC-Z in page 3, ...

View 4 Replies View Related

Collapsing/Expanding Group Data In Table And Matrix Data Regions

May 30, 2007

Hi,



Is it possible to create Expand/Collapse functionality for the grouped data in Table and Matrix data regions? Essentially, the idea is for the user to be able to see the group/subgroup data if she wishes to by clicking on (+/-) symbols, as is usually the case in Tree View style data grid control in web apps. Any ideas how to accomplish the same in reporting services?



Thanks.

View 1 Replies View Related

Group Data By Weeks

Apr 22, 2008

hi, I am trying to group my data into weeks in a month.
I am using :
GROUP BY DateAdd(day, -1 * datepart(dw, convert(char(10),date1,23)),
convert(char(10),date1,23))

Which works ok, but my first day is the monday of each week.
Do you know how I can group by weeks,
where dates run from monday to sunday ?
So IN march I would have

week begin 3/3
week begin 10/3
week begin 17/3
week begin 24/3
week begin 31/3

But for the last day I only want to count the 31st, not the entire week.
Same goes for the beginning of the month,
eg for april, I want it to show as week beginning 31st march but I only count aprils data.

I hope that makes sense.

can you help ?

View 3 Replies View Related

How To Group Certain Rows And Get The Data.

Jul 2, 2007

Hi Folks,

I am stuck in forming a query.

My age wise employee count sample data (department wise) is as shown below.

Sample Data
-----------
Department [>55] [50-55] [<50] [<40] [<30]
---------- ----- ------- ----- ----- -----
Marketing 0 1 5 10 20
Op's Support 0 3 6 5 25
Op's Tech 0 0 0 3 10
Product Tech 0 0 2 4 12
Product Support 0 0 1 3 7

I would require the data (sum of employee count age wise) to be categorized at a boarder level. Each category comprising of one or more departments.

Operations [Op's Support + Op's Tech], Product [Product Tech + Product Support], Others [Marketing]
The expected result would be.

Category [>55] [50-55] [<50] [<40] [<30] [Total]
--------- ----- ------- ----- ----- ----- -------
Operations 0 3 6 8 35 52
Product 0 0 3 7 19 29
Others 0 1 5 10 20 36

Thanking you in anticipation.

Jabez.

View 4 Replies View Related

Group Data By Month

Feb 20, 2008

Hi,
how can i group data using specified date like for example per month.
here is my sample data.

fielddate | fieldnumber
january 1, 2007 | 1
january 5, 2007 | 2
February 2, 2007| 3
March 4, 2007 | 3
March 5, 2007 | 4

i want to sum all fieldnumber by month
result will be:

resultdate | resultnumber
january 2007 | 3
February 2007 | 3
March 2007 | 7

thnx for the help in advance.

View 3 Replies View Related

GROUP BY For Heirarchical Data

Mar 7, 2008

I have a table:

ID int, AreaID int, SaleAmount float, SaleDate smalldatetime

AreaID is an foreign key to a second table of heirarchical area data:

ID int, ParentId int, AreaName nvarchar.

The heirarchy varies in depth for different parts of the country - sometimes 3 levels deep, sometimes up to six.

My problem is this: how do a construct a sproc that will allow me to pass in any area id and then return one or more result sets with all the child data of that area id grouped (to allow a SUM() of the sales data and a MIN() of the dates) by EACH LEVEL of the heirarchy?

Sales data only exists in the bottom one or two levels.


I've tried looking at CTEs but can't seem to crack the problem. I got close with a WHILE loop, but that kept grouping the data at the same level.....

Thanks

John

Expected output from this data if, say, I passed in 1 (the National level)

'National', 47.81, 20-Feb-08
'Super Region A', 37.81, 21-Feb-08
'Region 1', 16.81, 21-Feb-08
'Region 2', 21.00, 22-Feb-08
'Sub Region 1', 8.81, 21-Feb-08
'Sub Region 2', 8.00, 22-Feb-08
'Sub Region 3', 7.70, 23-Feb-08
'Sub Region 4', 12.30, 22-Feb-08

and so on. Note that it doesn't have to be one table - each level could come back as a separate table (in fact, that might be helpful).

If I passed in 3 I'd get

'Region 1', 16.81, 21-Feb-08
'Sub Region 1', 8.81, 21-Feb-08
'Sub Region 2', 8.00, 22-Feb-08


(NB these results are just typed in, so forgive typos please, and the sums and min dates are not necissarily the same as from the sample
data below)

CREATE TABLE [dbo].[SalesData](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[AreaID] [int] NULL,
[SalesDate] [smalldatetime] NULL ,
[SalesAmount] [float] NULL
)


CREATE TABLE [dbo].[SalesAreas](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ParentID] [int] NOT NULL ,
[Name] [nvarchar](64) NOT NULL
)

DECLARE @ID int
DECLARE @ID2 int
DECLARE @ID3 int

INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( 0, 'National') --1
SELECT @ID = @@IDENTITY
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID, 'Super Region A')--2
SELECT @ID2 = @@IDENTITY

INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID2, 'Region 1') --3
SELECT @ID3 = @@IDENTITY
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 1') --4
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 2') --5

INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID2, 'Region 2') --6
SELECT @ID3 = @@IDENTITY
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 3') --7
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 4') --8

INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID, 'Super Region B')--9
SELECT @ID2 = @@IDENTITY

INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID2, 'Region 3') --10
SELECT @ID3 = @@IDENTITY
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 5') --11
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 6') --12
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 7') --13

INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID2, 'Region 4') --14
SELECT @ID3 = @@IDENTITY
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 8') --15
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 9') --16
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 10') --17
INSERT INTO SalesArea ([ParentID], [Name]) VALUES ( @ID3, 'Sub Region 11') --18



INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (4, DATEADD(d,-5, GETDATE()), 3.49)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (4, DATEADD(d,-6, GETDATE()), 2.81)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (5, DATEADD(d,-8, GETDATE()), 4.14)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (5, DATEADD(d,-9, GETDATE()), 1.89)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (5, DATEADD(d,-2, GETDATE()), 1.02)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (5, DATEADD(d,-3, GETDATE()), 3.13)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (7, DATEADD(d,-4, GETDATE()), 5.12)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (7, DATEADD(d,-4, GETDATE()), 6.17)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (7, DATEADD(d,-1, GETDATE()), 3.49)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (8, DATEADD(d,-4, GETDATE()), 4.29)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (8, DATEADD(d,-5, GETDATE()), 4.46)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (11, DATEADD(d,-6, GETDATE()), 3.33)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (11, DATEADD(d,-1, GETDATE()), 3.92)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (12, DATEADD(d,-7, GETDATE()), 5.89)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (13, DATEADD(d,-5, GETDATE()), 6.16)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (13, DATEADD(d,-3, GETDATE()), 3.34)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (15, DATEADD(d,-2, GETDATE()), 2.61)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (15, DATEADD(d,-3, GETDATE()), 5.12)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (16, DATEADD(d,-4, GETDATE()), 8.28)
INSERT INTO SalesData (AreaID, SalesDate, SalesAmount) VALUES (17, DATEADD(d,-5, GETDATE()), 2.44)

View 14 Replies View Related

USING 'CASE' TO GROUP DATA

Aug 22, 2006

Hi,Can anyone please help me with SQL syntax to create a second variablebased on the value of another (both numeric)?My effort is below but I get a syntax error.SELECTcharA,CASE charAWHEN < -199 THEN 2WHEN < 31 THEN 3WHEN < 82 THEN 4WHEN < 100 THEN 5WHEN < 105 THEN 6WHEN < 111 THEN 7WHEN < 143 THEN 8WHEN < 165 THEN 9WHEN < 233 THEN 10WHEN >= 233 THEN 11END AS Bin_charAFROM XServer: Msg 170, Level 15, State 1, Line 6Line 6: Incorrect syntax near '<'.

View 3 Replies View Related

Group Data By Weeks

Nov 2, 2006

I have data entered into a table using a datetime field. How can I group the data one week at a time and show mulitple weeks at a time?

View 14 Replies View Related

Using Group By For Text Data Type

May 22, 2006

Hi,I have a problem on an old app. This application is a Help Desk, any Computer related problem (Motherboard Burn Out, Software Crash, dll) on my company will be recorded using this Help Desk application.One month ago, some programmer found a bug in this program lead to many duplicate data on database. But too late, This program has entered production stage and used for more than 2 years. This bug only happen at some condition so I found out after 2 years running (when my boss reported there are some duplicate data on "helpDesk" table).The bug is solved but helpDesk table need some "cleaning" operation. Here is structure of that table :helpDesk Table- id (primary key, integer auto increment)- reported_by (varchar 200)- problem_title (varchar 200)- problem_description (text)- date_summited (datetime)well usualy if I want to find some duplicate data I wil type :SELECT     MAX(uid) AS uid, reported_by, problem_title, COUNT(uid) AS total_duplicateFROM         problemsGROUP BY problem_title, problem_description,uidHAVING      (COUNT(uid) > 1)But that query will not work because problem_description data type is "text" which not support "group by" statement.Any other Idea how to locate and cleaning up this duplicate data?thanks

View 2 Replies View Related

SQL Server 2014 :: How To Sum And Group Data

Jan 20, 2015

I want to group the following data attached by CUSTACCT, YEAR, PERIOD(month). As you can see in the attached example, I see duplicates for late fees and Exchange fees but none for FLIGHT_HRS. I want to see the data grouped by CUSTACCT by YEAR then by PERIOD for each of these: FLIGHTHRSSUM, LATEFEESUM, EXCHFEESUM without duplicates.

Is this possible?

This is my current SQL

SELECT dbo.VIEW_FLIGHT_HRS_TOT.YEAR AS FLTHRSYEAR, dbo.VIEW_FLIGHT_HRS_TOT.PERIOD AS FLTHRSPERIOD, dbo.VIEW_FLIGHT_HRS_TOT.FLIGHTHRSSUM,
dbo.VIEW_LATE_FEES_TOT.PERIOD AS LATEFEEPERIOD, dbo.VIEW_LATE_FEES_TOT.YEAR AS LATEFEEYEAR, dbo.VIEW_LATE_FEES_TOT.LATEFEESUM,

[Code] ....

View 9 Replies View Related

Selecting Distinct Data Using Group By

Aug 4, 2013

I have an action log table which records when a registrant record was viewed by a compnay employee. I have an sql query like this:

SELECT [ID]
,[RegistrantID]
,[EmployeeID]
,[UserID]
,[CompanyID]

[Code] ....

and data is like this:

IDRegistrantID EmployeeIDUserID CompanyID VacancyID Action ActionDate
17931629515163213NULL 42013-08-04 16:45:40.457
17921629215163213NULL 42013-08-04 16:45:33.003
1791NULL15163213NULL 32013-08-04 16:45:23.660
1790162959162893NULL 42013-08-04 16:45:09.543

[Code] ....

I want to select distinct views to a registrantid record ( the first ones) in one year. if a registrant was viewed 10 tmes a year then it will show only first time it was viewed. If it was viewed 10 times by an employeed in 2 years then it will show first time it was viewed. if it was viewed by 2 employees of same company 10 times in one year then it first time viewed record will be shown. if it was seen 10 times by 2 employees of two different companies in one year then first record of two companies will be shown. do i need to use group by or what ?

View 1 Replies View Related

Problem With Data Group Label

May 14, 2008

Can anyone tell me why the following returns a warning and does not work:




Code Snippet=IIf(InStr(Fields!Unit.Value,"-") > 0, Left(Fields!Unit.Value,InStr(Fields!Unit.Value,"-")-1),Fields!Unit.Value)





but the following does work as expected:




Code Snippet=IIf(InStr(Fields!Unit.Value,"-") > 0, Left(Fields!Unit.Value,3),Fields!Unit.Value)





The warning message that I get is:


[rsRuntimeErrorInExpression] The HeadingLabel expression for the chart €˜chart4€™ contains an error: Argument 'Length' must be greater or equal to zero.



What I am trying to do is only display the text preceding the "-" if it exists within the text otherwise just show the text as it is.

Thanks

View 3 Replies View Related

Displaying Group Headers Even When No Data?

Mar 20, 2008

I have a table where I need to display groupings of information. If there isn't any data for a given group, I still need to include that group and say "no applicable data" or somesuch underneath it. Any way of doing this?

View 1 Replies View Related

Transact SQL :: Difference Between Data With Group By

Jul 28, 2015

I have a SQL table like this

Events time endTime
Tram 2014-11-28 12:35:50.390 2014-11-28 12:43:19.120
Re-Entry 2014-11-28 12:43:19.120 2014-11-28 12:56:07.040
Tram 2014-11-28 12:56:07.040 2014-11-28 13:15:25.060 // EndDate Before dump
Dump 2014-11-28 13:15:25.060 2014-11-28 13:50:07.233
Tram 2014-11-28 13:50:07.233 2014-11-28 13:55:17.473
Load 2014-11-28 13:55:17.473 2014-11-28 14:06:55.063
Tram 2014-11-28 14:06:55.063 2014-11-28 14:37:12.100
Dump 2014-11-28 14:37:12.100 2014-11-28 14:37:12.100

I want to calculate the Difference between 2 dates like endtime before Dump -time..I am expecting output like this

ROW1   ROW2
 1    00:39:34
 2    23:12:55

You can find the details in SQL Fiddle here.

View 4 Replies View Related

Getting Access To The Data In Group 2 From Group1

Mar 30, 2007

I have a table with two groups.. like this

Table Header

Group 1 Header

Group 2 header

Detail

Group 2 footer

Group 1 footer

Table footer





I have a field value in group 2, I need to sum that field value in group 1.

Is there any way to do this? I thought you could go inwards in scope but not outwards?

View 1 Replies View Related

Adding Nongrouped Data Into Group Row

Feb 6, 2006

This may sound a bit weird...but here it goes.  I have in my SSRS 2005 report one table.  In that table I have:

Header1

Groupp1

Footer1

Some of the fields in the Group look like this:

Company Number    Branch    FeeGoal

 The problem I have is FeeGoal.  It comes from a table that is simply joined to my main dataset (via the dataset's stored proc) on company number.   So I do not want this one summed.  I want it to be the value the user entered for that company only, not summed.  I have an ASP.NET input form where each of the companies has one FeeGoal input field.  I then update all company records in a temp table where they have a FeeGoal field....and update each FeeGoal Field for that company with the FeeGoal the user entered into my form.

IN the report group, I do not put sum for this field, I just put

=Fields!FeeGoal.Value

So that I end up with basically Top 1 of FeeGoal for the particular company in the group.  The problem I have now is how to sum up all FeeGoals without summing up of the same FeeGoal values for each company.  Remember, I just want to sum up all Top 1 values for FeeGoal in the Group.

How do I do this? 

 

Sample Data

CompanyName Field1 Field2  FeeGoal
ABC           100   2000    200000
ABC           100    232    200000
ABC           112      2    200000
DCE            23    223    300000
DCE           203    200    300000
DCE            24    229    300000
EER            22    344    400000
EER           220    111    400000

Picture that as my Dataset

Now in my Report, I have the followingfields in my Group, grouped by CustomerNumber(not shown)

Group1
CustomerName   Field1    Field2    FeeGoal

In my FeeGoal, I simply put =Fields!FeeGoal.Value, not =SUM(Fields!FeeGoal.Value) because I want to only sum Distinct, not 30000 + 30000 + 30000 for example..I only want to show 300000 for Company DCE

But in the Footer, I put the same Fields!FeeGoal.Value.  Of course that only returns the top result which is 20000 for company ABC.

If I then try =SUM(Fields!FeeGoal.Value), it's way over inflated because it's counting the FeeGoal multiple times per customer, I only want to sum up each common instance.

FeeGoal is a unique case, usually you let the grouping do it's work but I don't want to overinflate my total for FeeGoal in my Footer.

If there is some way to do =SUM(Top 1 FeeGoal) or SUM(Distinct FeeGoal) in SSRS 2005 VB syntax somehow in the expression builder, this is the only way to get this to be accurate unless someone else knows...

Here's a couple of screen shots.  You'll see the overinflated FeeGoal sum:

http://www.photopizzaz.biz/feegoal1.jpg
http://www.photopizzaz.biz/feegoal12.jpg

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved