locked
Help with SELECT RRS feed

  • Question

  • User-735851359 posted

    Hello,

    I have a Query which gives the companies. But I need to list the companies with ONLY Video. If the Video field is NOT EMPTY OR NOT NULL, it must be listed.

    So for I used IsNullOrEmpty, but I want to get rid of that.

    Here is the my code:

        var comps2 = data.Query("SELECT CompanyID, CompanyName, Visited,  Video FROM Companies ORDER BY Visited DESC").ToList();
    

    Then

      for(int i=0;i<comps2.Count;i++){
        if(!String.IsNullOrEmpty(comps2[i].Video)){
    

    How can I do that only using Query (with WHERE clause) without IF code.

    Thanx in advance!

    Wednesday, January 7, 2015 4:21 PM

Answers

  • User1853794821 posted
    SELECT CompanyID, CompanyName, Visited,  Video FROM Companies 
    WHERE (video is not null) and Video <> ''
    ORDER BY Visited DESC

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 7, 2015 4:29 PM
  • User895691971 posted

    You can make a good use of the following command, 

    var comps2 = data.Query("SELECT CompanyID, CompanyName, Visited, Video 
                             FROM Companies 
                             WHERE Video IS NOT NULL
                             ORDER BY Visited DESC")

    This is a IS NOT NULL command, which makes sure that in the rows returned the value for the Video is not a null value. Read this MSDN command for more: http://msdn.microsoft.com/en-us/library/ms188795.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 7, 2015 4:30 PM

All replies

  • User1853794821 posted
    SELECT CompanyID, CompanyName, Visited,  Video FROM Companies 
    WHERE (video is not null) and Video <> ''
    ORDER BY Visited DESC

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 7, 2015 4:29 PM
  • User895691971 posted

    You can make a good use of the following command, 

    var comps2 = data.Query("SELECT CompanyID, CompanyName, Visited, Video 
                             FROM Companies 
                             WHERE Video IS NOT NULL
                             ORDER BY Visited DESC")

    This is a IS NOT NULL command, which makes sure that in the rows returned the value for the Video is not a null value. Read this MSDN command for more: http://msdn.microsoft.com/en-us/library/ms188795.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 7, 2015 4:30 PM