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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need help with SQL stored procedure

Author  Topic 

art2k
Starting Member

3 Posts

Posted - 2010-05-03 : 21:13:48
with these following steps.


1- An SQL statement that creates a stored procedure with one int input parameter. The stored procedure selects the supplierId field and the total of all Count field values for each group of supplierId's from the Part table. Only rows with their Count total, or sum, greater than the value specified in the input parameter.

2- Write a SQL statement that creates a stored procedure that adds a new record to the (Part) table, and returns the value of the newly created PartID PK in an out parameter. The field values of the record to be added should be passed into the stored proc as input parameters. The assumption here is that the (Part) table has its PartID PK field as an idendity field, or surrogate PK, meaning a numeric field that is auto-generated by the db system.


3- Write a SQL statement that creates a user defined function that returns an int value. This int return value is obtained by subtracting the lowest Count field value from the highest Count field value of the (Part) table.


4- Create an Update trigger on the Part table that raises an error string if the Count field of the updated row has a higher value than the value prior to the Update. In other words, the new value cannot be larger than the older value. If the trigger fires and after the error string is displayed, the Update operation should be rolled back. The exact text of the error string is up to you to define.

Thanks...

RobertKaucher
Posting Yak Master

169 Posts

Posted - 2010-05-03 : 21:55:20
This sounds like homework. Could you post any work you have already done and questions you might have regarding said work?

===
http://www.ElementalSQL.com/
Go to Top of Page

art2k
Starting Member

3 Posts

Posted - 2010-05-03 : 21:59:41
this is what i have so far...

CREATE PROCEDURE week5procedure
@supplierID int,
@CountID int,
AS
INSERT INTO week5procedure(supplierID,CountID)
VALUES(@supplierID,CountID);

CREATE PROCEDURE addnewrecord


i am completely lost
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 03:54:52
it clearlt states you need to group on supplierid.have a look at syntax of GROUP BY. that should give you a start.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -