2016-10-15 97 views
1
SELECT 
    ROW_NUMBER() OVER (ORDER BY Vendor_PrimaryInfo.Vendor_ID ASC) AS RowNumber, 
    * 
FROM 
    Unit_Table 
INNER JOIN 
    Vendor_Base_Price ON Unit_Table.Unit_ID = Vendor_Base_Price.Unit_ID 
INNER JOIN 
    Vendor_PrimaryInfo ON Vendor_Base_Price.Vendor_ID = Vendor_PrimaryInfo.Vendor_ID 
INNER JOIN 
    Vendor_Registration ON Vendor_Base_Price.Vendor_ID = Vendor_Registration.Vendor_ID 
         AND Vendor_PrimaryInfo.Vendor_ID = Vendor_Registration.Vendor_ID 
INNER JOIN 
    Category_Table ON Vendor_Registration.Category_ID = Category_Table.Category_ID 
LEFT JOIN 
    Vendor_Value_Table ON Vendor_Registration.Vendor_ID = Vendor_Value_Table.Vendor_ID 
LEFT JOIN 
    Feature_Table ON Vendor_Value_Table.Feature_ID = Feature_Table.Feature_ID 
WHERE 
    Vendor_Registration.Category_ID = 5 
    AND Vendor_PrimaryInfo.City = 'City' 
    AND (value_text in ('sample value') or 
     (SELECT 
       CASE WHEN ISNUMERIC(value_text) = 1 
         THEN CAST(value_text AS INT) 
         ELSE -1 
       END) BETWEEN 0 AND 100) 

由於列有多個值,可能是文本或可能是int,這就是爲什麼我基於大小寫投射。我的問題是:我只想獲取記錄的值在0到100之間,或者值在300到400之間,或者值類似於樣本值。如何在where子句之後提供多個值子句

我只想部位的條件後,where子句和不想使用欄多的時間在運營商之間因爲這些值是從網址提前到來

感謝任何幫助,將不勝感激。

+0

你想另一個條件爲100-200之間?對於300-400? –

+0

@AmirZiarati是條件被追加,如300和400或400或500之間的需要等,也不想多次使用value_text列 – user1870546

+0

這種行爲意味着動態查詢。這需要在代碼方面完成。例如,如果您的編碼爲asp.net,則需要進行動態查詢並根據需要應用。例如,如果你需要另一個或另外三個之間你做一個for循環,並追加到您的新條件查詢,然後運行quru –

回答

0

你可以試試這個方式..

WHERE 
    Vendor_Registration.Category_ID = 5 
    AND Vendor_PrimaryInfo.City = 'City' 
    AND (value_text in ('sample value') or 
     (CASE WHEN (ISNUMERIC(value_text) = 1) 
         THEN CAST(value_text AS INT) 
         ELSE -1 
       END) BETWEEN 0 AND 100) 
+0

然後我怎麼能通過運營商之間的下一個值在這裏? – user1870546

+0

值是來自案例...你有沒有試過這個? –

+0

錯誤的語法,然後 – user1870546