Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a stored procedure

Status
Not open for further replies.

dolodolo

Technical User
May 27, 2003
86
0
0
US
Hi,

I need help with conventions on turning a script into a stored procedure. here's the script:
/* Version 1.0
DESCRIPTION
Create Temporary Tables for Updating Minimum and Maximum Rent on Floorplan table
Created by d.meehan 4/23/2010 */


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TEMP_UPDATE_FLOORPLAN]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TEMP_UPDATE_FLOORPLAN];

CREATE TABLE TEMP_UPDATE_FLOORPLAN (
hproperty numeric(18, 0) NOT NULL ,
hfloorplan numeric(18, 0) NOT NULL ,
sname varchar(50) NULL,
dminrent numeric (21,6) NULL,
dmaxrent numeric (21,6) NULL,
datecreated datetime NULL);


/* Insert records into TEMP_UPDATE_FLOORPLAN */

INSERT INTO temp_update_floorplan ( hproperty, hfloorplan, sname, dminrent, dmaxrent, datecreated)

(select
p.hmy,
f.hmy,
f.sname,
min(u.srent),
max(u.srent),
Getdate()
from unit u
inner join unittype ut on ut.hmy = hunittype
inner join property p on p.hmy = u.hproperty
inner join floorplanxref fx on fx.hunittype = ut.hmy
inner join floorplan f on f.hmy = fx.hfloorplan
where p.binactive = 0
and substring(ut.scode,1,1) not in ('x', 'd')
and substring(ut.scode,5,1) not in ('x', 'z')
and substring(u.scode,1,4) <> 'WAIT'
and isnull(u.bportalexcluded,0) = 0
and ut.sdesc not like '%AFFORD%'
and u.srent <> 0
group by p.hmy,
f.scode, f.sname, f.hmy);

/* Update Floorplan with TEMP_UPDATE_FLOORPLAN min/max rents. */

update floorplan set
drentlow = tf.dminrent,
drenthigh = tf.dmaxrent
from temp_update_floorplan tf
where tf.hfloorplan = floorplan.hmy;

Any help would be appreciated - thanks!
 
Look up CREATE PROCEDURE in BOL

Start SSMS start a new query go to the database where you want the SP (USE mydatabase;) then add CREATE PROCEDURE myProcedure AS to your code above.


djj
The Lord is My Shepard (Psalm 23) - I need someone to lead me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top