472,961 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,961 software developers and data experts.

Hey I've got a homework problem I'm working on and am stumped.

It goes like the following:
Use AdventureWorks database and HumanResources.Department table.

Create a stored procedure called spDepartmentAddUpdate. This procedure
accepts two parameters: Name, and GroupName. The data types are
VarChar(50), and VarChar(50) respectively. Define logic in this
procedure to check for an existing Department record with the same Name.
If the department record exists, update the GroupName and ModifiedDate.
Otherwise, insert a new department record.

A. Execute your stored procedure to show that the insert logic works.
B. Execute your stored procedure to show that the update logic works.

Any hints from the wizards out there would be greatly appreciated!

*** Sent via Developersdex http://www.developersdex.com ***
Aug 10 '06 #1
6 1193
Nep Tune (ne*******@go.com) writes:
It goes like the following:
Use AdventureWorks database and HumanResources.Department table.

Create a stored procedure called spDepartmentAddUpdate. This procedure
accepts two parameters: Name, and GroupName. The data types are
VarChar(50), and VarChar(50) respectively. Define logic in this
procedure to check for an existing Department record with the same Name.
If the department record exists, update the GroupName and ModifiedDate.
Otherwise, insert a new department record.

A. Execute your stored procedure to show that the insert logic works.
B. Execute your stored procedure to show that the update logic works.

Any hints from the wizards out there would be greatly appreciated!
If you are not able to carry out your homework assignments, you should
talk to the teacher, rather than sneak behind his back. Your teacher
knows what you are supposed to know, and what you yet have to learn.

But permit me to not that the parameters to the procedure should really
be nvarchar(50) and not varchar(50) to go along with the table definition.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 10 '06 #2
YOU WRITE:
you should talk to the teacher, rather than sneak behind his back. Your
teacher knows what you are supposed to know, and what you yet have to
learn.
I WRITE:
Well, thanks for the suggestions. You and my teacher ought to team
teach; I'd learn about the same from both of you: NOTHING!

*** Sent via Developersdex http://www.developersdex.com ***
Aug 12 '06 #3
Nep Tune (ne*******@go.com) writes:
I WRITE:
Well, thanks for the suggestions. You and my teacher ought to team
teach; I'd learn about the same from both of you: NOTHING!
Ah, but there is a difference! He is paid to teach you to nothing.

On a more serious note, newsgroups are not the best place to learn. If
someone asks a "how do I write this query", it can be fairly simple to
write that query, provided that the question is clear enough. But
explaining what is actually happening can be a lot more difficult, and
I usually don't do that in my posts. That's OK if the poster has some
experience and has run into a little more difficult problem at work.
If he is interested he will try to understand the solution and use it.

If he is not interested, well at least he got help with doing his part
in his work. After all, it could be that SQL is something he does left-
hand and his main skills are with VB, C++ or whatever. And I would expect
him to be able to write the procedure you were asked to.

Anyway, some hints: you will need to use INSERT and UPDATE. You will also
learn to master IF EXISTS. If you ever grow up to be a developer, you
will write tons of such procedures in your career! :-)
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 12 '06 #4
On 12 Aug 2006 13:59:56 GMT, Nep Tune <ne*******@go.comwrote:
>YOU WRITE:
you should talk to the teacher, rather than sneak behind his back. Your
teacher knows what you are supposed to know, and what you yet have to
learn.
I WRITE:
Well, thanks for the suggestions. You and my teacher ought to team
teach; I'd learn about the same from both of you: NOTHING!
What the hell do you expect, when your initial post amounts to "please
do my entire assignment for me"? Now if you demonstrated some prior
effort on your own part - e.g. "I tried so-and-so, but it gets
such-and-such wrong, and I don't know how to proceed from there" -
then I bet people would be a lot more willing to help out.
Aug 12 '06 #5
> Create a stored procedure called spDepartmentAddUpdate. <<

The "sp-" prefix violates ISO-11179 rules. Even Microsoft gave up on
camelCase because it is a bitch to read.
>This procedure accepts two parameters: Name, and GroupName. <<
"name" is too vague to be a data element -- naem of what?
>The data types are VarChar(50), and VarChar(50) respectively. <<
See prior remark about camelCase. This should be NVARCHAR(n) where (n)
was actually researched . Please post DDL, so that people do not have
to guess what the keys, constraints, Declarative Referential Integrity,
data types, etc. in your schema are. Sample data is also a good idea,
along with clear specifications. It is very hard to debug code when
you do not let us see it.
> Define logic in this procedure to check for an existing Department record [sic] with the same Name [was this the key in the DDL you did not post?]. If the department record [sic] exists, update the GroupName and ModifiedDate. Otherwise, insert a new department record [sic]. <<
Rows are not records; fields are not columns; tables are not files.
This is foundations.

No auditor will allow you to put "modified_date" in a table. Audit
trails have to be separate from the data by law (see SOX compliance
rules), by GAAP and by common sense.
>Any hints from the wizards out there would be greatly appreciated! <<
At every school I have taught or at which I have been a student,
presenting the work of other people as your own will get you kicked
out. So far, I have ended the college education of two cheaters, one
in New Zealand and one in the US by reporting them to their
departments. Is that enough of a hint?

Aug 13 '06 #6
--CELKO-- (jc*******@earthlink.net) writes:
>>The data types are VarChar(50), and VarChar(50) respectively. <<

See prior remark about camelCase. This should be NVARCHAR(n) where (n)
was actually researched . Please post DDL, so that people do not have
to guess what the keys, constraints, Declarative Referential Integrity,
data types, etc.
No, Joe. Get yourself a copy of SQL 2005 and install the AdventureWorks
database. NepTune may be cheating with his homework. But he gave all
necessary information to solve the problem.
No auditor will allow you to put "modified_date" in a table. Audit
trails have to be separate from the data by law (see SOX compliance
rules), by GAAP and by common sense.
I don't think AdventureWorks Bicycles has any auditor...
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: N3TB1N | last post by:
Let me try again. I could use some help with this assignment, even though my teacher does not grade assignments.but because I need to know this stuff for a test very soon, but haven't been in...
3
by: Workaholic | last post by:
Hi, I have a problem that I have now seen on two different servers. I have a VB.Net application that is installed on the servers. It works fine on both servers. If I make a change to the...
7
by: mastern200 | last post by:
For Homework, i have to debug a program (I am a noob!) it is a voting program where you put in the amount of votes a certain candidate gets and evaluates by showing how many votes, what percentage of...
2
by: Steven Chumney | last post by:
Exam week is here and we do not have our projects complete. If anyone is willing to help we would greatly appreciate it. These are probably simple for someone with experience, but we are completely...
3
by: Randy Magruder | last post by:
Hi all, I hope someone here can diagnose what I'm seeing because I'm stumped. I have an asp.net 1.1 application with a login page. I have loaded up the Page_Load( ) with trace messages and...
8
by: teddarr | last post by:
OK I'm having trouble with this problem on my homework. I got the rest OK, I don't know why this problem is stumping me. List the number of rooms in each hotel. Tables: HOTEL: (hotelNo,...
1
by: wvueagle84 | last post by:
I have the following code in which I am attempting to break a large image up in 16x16 blocks and perform some processing on those blocks. For debugging I would like to save each of the 16x16 blocks...
1
by: itgetsharder | last post by:
Hey, i was wondering if anyone could help me. i have two questions that i cannot complete for a homework assignment: This method should convert its parameter (a string like "3.1415") to the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.