TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jes Sie
744
1.2k
282.3k
How to get the Min and Max in SQL SERVER
Aug 20 2019 2:12 AM
Below is my table in SQL SERVER. What I want is to extract the lowest partsCost and the latest partsCost inserted into the table:
Below is my stored procedure but does not work:
ALTER
PROCEDURE
[dbo].[spClaims_GetLowestLatestPrice]
--'honda','civic','1'
-- Add the parameters for the stored procedure here
@carMake nvarchar(50),
@carModel nvarchar(50),
@partsCode
int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET
NOCOUNT
ON
;
-- Insert statements for procedure here
with
query1
as
(
SELECT
ISNULL
(partsCost,0)
AS
LowestPrice
FROM
claimsPartsMasterList
WHERE
carMake = @carMake
AND
carModel = @carModel
AND
partsCode = @partsCode
AND
partsCost = (
SELECT
MIN
(partsCost)
FROM
claimsPartsMasterList
AS
LowestPrice)),
query2
as
(
SELECT
ISNULL
(partsCost,0)
AS
LatestPricePurchase
FROM
claimsPartsMasterList
where
carMake = @carMake
AND
carModel = @carModel
AND
partsCode = @partsCode
AND
getLogs = (
SELECT
MAX
(getLogs)
FROM
claimsPartsMasterList
AS
LatestPricePurchase))
SELECT
LowestPrice, LatestPricePurchase
from
query1, query2
END
Hope someone can help with this. Thanks in advance.
Reply
Answers (
4
)
csharp threading
storing dynamic ComboBox value into database and retreiving