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!

Help with stored procedure 1

Status
Not open for further replies.

pyttviper

MIS
May 15, 2001
37
0
0
US
i am new to SPs and i need some basic answers
i wrote the below querie which returns a number but i want to store that number in a variable.
Code:
CREATE PROCEDURE sp_ac6000_metric_load 
AS
SELECT 	count(diffdays)as counts
FROM	(SELECT ID, 
		Initial_Date, 
		getdate() AS Today,
		 DateDiff(day,Initial_Date,getdate()) AS diffDays, 
		left(Active,1) as active, 
		left(Railroad,4)as rail , 
		left(REMOTE_MON_REC,10) as REC 
	FROM 	ac6000_loco_data 
	WHERE Initial_Date<>'' AND 
		ac6000_loco_data.Active='Y'  AND 
		ac6000_loco_data.remote_mon_rec<>'' AND 
		ac6000_loco_data.Railroad='up') as DTA
 
if ur question is how to return the count value as a variable then
SELECT VariableName = count(diffdays)as counts
FROM (SELECT ID,
Initial_Date,
getdate() AS Today,
DateDiff(day,Initial_Date,getdate()) AS diffDays,
left(Active,1) as active,
left(Railroad,4)as rail ,
left(REMOTE_MON_REC,10) as REC
FROM ac6000_loco_data
WHERE Initial_Date<>'' AND
ac6000_loco_data.Active='Y' AND
ac6000_loco_data.remote_mon_rec<>'' AND
ac6000_loco_data.Railroad='up')

Let me know its helpful or not
 
i tried this and i can't get it to work

CREATE PROCEDURE sp_ac6000_metric_load
AS
@uptotal int
SELECT @uptotal = count(diffdays)as counts
FROM (SELECT ID,
Initial_Date,
getdate() AS Today,
DateDiff(day,Initial_Date,getdate()) AS diffDays,
left(Active,1) as active,
left(Railroad,4)as rail ,
left(REMOTE_MON_REC,10) as REC
FROM ac6000_loco_data
WHERE Initial_Date<>'' AND
ac6000_loco_data.Active='Y' AND
ac6000_loco_data.remote_mon_rec<>'' AND
ac6000_loco_data.Railroad='up') as DTA


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top