chrisdoesstuff
Technical User
SQL express 2008
My data contains a set of values that I'd like to use parts of in a query. (this isn't real data I'm just trying to fully grasp the concept)
Ex animals.value and the values are 'Rhino', 'Leopard', 'Cheetah', 'Monkey'
I want to insert the data into a table variable but only if it's cheetah or monkey and I want to be able to select cheetah as ground and monkey as tree in my final query.
I started to use
Insert into @zooanimals SELECT value, location from animals where animals.value = 'cheetah" or animals.value = 'monkey'
However that doesn't work as I only end up with one row. Should I be selecting it differently in my final query? What's the easiest way to accomplish this?
My final query will be like
SELECT fac.code, fac.location ani.value, ani.location
from Facilities fac
Left outer join animals ani
on fac.location = ani.location
should give me all the facilities and show me which ones have animals that are cheetah or monkey and in the case of cheetah and monkey being in the same location it can show both in separate columns.
Any help you can provide is appreciated
My data contains a set of values that I'd like to use parts of in a query. (this isn't real data I'm just trying to fully grasp the concept)
Ex animals.value and the values are 'Rhino', 'Leopard', 'Cheetah', 'Monkey'
I want to insert the data into a table variable but only if it's cheetah or monkey and I want to be able to select cheetah as ground and monkey as tree in my final query.
I started to use
Insert into @zooanimals SELECT value, location from animals where animals.value = 'cheetah" or animals.value = 'monkey'
However that doesn't work as I only end up with one row. Should I be selecting it differently in my final query? What's the easiest way to accomplish this?
My final query will be like
SELECT fac.code, fac.location ani.value, ani.location
from Facilities fac
Left outer join animals ani
on fac.location = ani.location
should give me all the facilities and show me which ones have animals that are cheetah or monkey and in the case of cheetah and monkey being in the same location it can show both in separate columns.
Any help you can provide is appreciated