![]() |
| ||
| Get All Rows In Column In A Where Statment MSSQL Where Statement Problem I want to select all in a column if variable = null I am placing a php variable in there and i know how to do that so i no that is not the problem but i want a where statement to return all rows of its column when it is null SELECT * I want this to select all and not just null rows if somone can help me out i would really appreciated it! :eek: |
| ||
| Re: Get All Rows In Column In A Where Statment not familiar with php but i think you need to put in an if clause on the php side that goes something like if (variable = null) select * from mytablename else select * from mytablename where mycolumnname = variable |
| ||
| Re: Get All Rows In Column In A Where Statment MSSQL Get One Column To Work With The Other Well, you are right i did that with my php. I used IF and ELSEIF statments in my php and then redirected the true statement to variables that then went into my MSSQL Statement for my query like this. This would be this first part if ($search1 == '') This say if variable is equal to null then $year_results (This is the variable that will be in my query statement) is equal to variable $allyears Now the second part is to assign a statment for variable $allyears like this $allyears = "(column1 < '2006') OR (column1 > '1900')";I used an between statement then i just placed the variable $year_results in my query statement like this $query = "SELECT * FROM databasename WHERE $submit_results AND $year_results"; Now that i did that it works just fine except i have came across another problem. I want to be able to show all the citys with a specific year so it will only show everything in the query for 2005, but the way i have my variables setup my query will look like this $query = "SELECT * FROM databasename WHERE (columnname2 = 'city1') OR (columnname2 = 'city2') OR (columnname2 = 'city3') OR (columnname2 = 'city4') AND (columnname1 = '2005') and well the city kinda overlap the year so either way it will show all the cities. So i just need to know if there is any way i can change this in my SQL so i can have all the cities show but only with ones with 2005 for the year. Sorry to be so long i just think this is really complicated. |
| ||
| Re: Get All Rows In Column In A Where Statment change it to $query = "SELECT * FROM databasename WHERE columnname2 in ('city1', 'city2', 'city3', 'city4') AND (columnname1 = '2005') or add parentheses in the right spot $query = "SELECT * FROM databasename WHERE ( (columnname2 = 'city1') OR (columnname2 = 'city2') OR (columnname2 = 'city3') OR (columnname2 = 'city4') )AND (columnname1 = '2005') |
| ||
| Re: Get All Rows In Column In A Where Statment Thanks that worked. Now all i have to do is configure my php Thanks |
| ||
| Re: Get All Rows In Column In A Where Statment i think all four replies are wrong for u if u r s=using SQL then u cant comapre null as u r doing the real statment is "select * from <table name> where isnull(<fldname>,'comparevalue')='comparevalue' the scenario is , in sql to comapre with null , u have to fill tht column with some value ,a nd then to compare that value to find the results of null, so use anyvalue to comapre abt whihc u r sure which cant be in ur field i normally use this command "select * from tablename where isnull(fldname='-')='-'" by assuming tht in my field "-" can't be . |
| ||
| Re: Get All Rows In Column In A Where Statment k thanks i will work with that and see want i can do. |
| ||
| Re: Get All Rows In Column In A Where Statment My next task is to find the addresses or business names in my database and well if i dont put in the exact information then i cant get that data. So i want to set up a wildcard or something that will let me get all information with that word in address or in business |
| ||
| Re: Get All Rows In Column In A Where Statment let's say your are looking for business named General Hardware. But you aren't sure if the name is General Hardware or General Tool Shop or something like that. What you want is select * from tblBusinesses where businessName like '%General%' Is that what you are looking for? |
| ||
| Re: Get All Rows In Column In A Where Statment Well sorta now i am having a problem with placing a variable in the syntax like this WHERE (MAS0030 LIKE '%$search8%') |
| All times are GMT -4. The time now is 3:16 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC