July 7, 2010 at 3:20 pm
I'm trying to find out if one field has the data from another field. Here is my situation. I have a field STSUB, which might have something like APT A in it. I then have another field called ADDRESS, which might have 123 Any Street APT A in it. I want to query the Address field and tell me if the data that is in STSUB is also in ADDRESS. So, I wrote this query
SELECT * FROM TABLENAME
WHERE ADDRESS LIKE STSUB
This didn't work, because the data in STSUB might be in ADDRESS; however, there is other data in there as well.
Any suggestion on how to do this?
Thanks,
Jordon
July 7, 2010 at 3:25 pm
You'd probably be better off doing some kind of string comparison, say something like this:
select * from tablename
where charindex(stsub, address) > 0
I don't know how well this will work with comparing columns, but maybe it'll point you in the right direction.
Hope this helps!
+--------------------------------------------------------------------------------------+
Check out my blog at https://pianorayk.wordpress.com/
July 7, 2010 at 3:28 pm
That worked perfect and give me all the records have has stsub as a part of address. Now, on the flip side of that, if I wanted to know all the records that doesn't have stsub as part of the address?
July 7, 2010 at 3:34 pm
Nevermind, I got it:
select * from tablename
WHERE charindex(stsub, address) = 0
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply