2014-01-11 54 views
0
ALTER PROCEDURE [dbo].[K_FS_GetFEEDMRPDetails] 
AS 
BEGIN 
SET NOCOUNT ON; 

    Select 
     FT.FeedType, 
     round(MR.rateperkg, 3) as rateperkg, 
     round(MR.rateper50kg, 3)as rateper50kg 
    from 
     K_FS_FeedMrpDetails MR 
    inner join 
     k_FPS_FeedType FT on FT.sno = MR.feedtype 
    where 
     date = convert(varchar(10), getdate(), 101) 
END 

此查詢顯示今日插入的數據。這是正確的,但我也想,如果今天沒有輸入任何數據,我想顯示上次輸入的數據。我怎樣才能做到這一點?請幫幫我......如何在SQL Server中獲取不同條件的數據?

+0

從什麼表的日期列where子句屬於? – Jade

+0

僅K_FS_FeedMrpDetails。 – santhosha

回答

1

該代碼會在你選擇最新插入的行

SELECT FT.FeedType, 
     Round(MR.rateperkg,3)As rateperkg, 
     Round(MR.rateper50kg,3)As rateper50kg 
FROM K_FS_FeedMrpDetails MR 
     inner join k_FPS_FeedType FT 
      On FT.sno=MR.feedtype 
WHERE date in (SELECT TOP 1 date FROM K_FS_FeedMrpDetails ORDER BY date Desc) 
+0

謝謝你的工作...... – santhosha

相關問題