Click to See Complete Forum and Search --> : more effectient way?


catchup
09-09-2006, 03:40 PM
hi this is what i have, i need the first value and last from the select statements. can this be done in a more effectient was, without having two selects? I there a attribute that handles such things? Thanks :)

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[spGetInventoryFirstValueAndLast]

@varProductID int,
@varRateEndDate varchar(20),
@prodID varchar(20),
@GDS int = 1,
@Available int

AS

Declare @MinDate DateTime
Declare @MaxDate DateTime

Select @MinDate = (Select Top 1 InventoryDate From Inventory
Where
Inventory.ProductID = @varProductID
AND Inventory.InventoryDate >= @varRateEndDate
AND Inventory.GDS=1
AND Inventory.prodID <> ''
AND Inventory.roomCode <> ''
AND Inventory.Available > 0
ORDER BY InventoryID ASC)


Select @MaxDate = (Select TOP 1 InventoryDate From Inventory
Where
Inventory.ProductID = @varProductID
AND Inventory.InventoryDate >= @varRateEndDate
AND Inventory.GDS = 1
AND Inventory.prodID <> ''
AND Inventory.roomCode <> ''
AND Inventory.Available > 0
ORDER BY InventoryID DESC)


Select @MinDate As MinDate, @MaxDate As MaxDate

russell_g_1
09-10-2006, 03:10 PM
try using the min and max functions.