Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 field that includes another field

Author  Topic 

toxicrainpx
Starting Member

8 Posts

Posted - 2008-03-13 : 13:09:34
Hello I'm newbie to SQL Server and I have a problem that I'm having dificult to solte. I have 2 tables one called st and another called inventario. Both have a field named ref. but st.ref have a data like 00222 and the inventario.ref have only 222. I want to test in a query a think like this :
Select * from inventarios where ref in(select ref from st)
It gives me less results because it only identifyes the correct data and escape the ones that have 00 or 000 before the number. My question is if the any way to make this query but instead of equal, if it's possible to use some thing that compares this 2 fields, like field that includes the content of another field.
Thanks in advance.

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-13 : 20:50:32


instead of = you can use RIGHT('00000' + st.ref,5) = RIGHT('00000' + inventario.ref,5)

If st.ref is a NUMBER, you will have to do +cast(st.ref as varchar(5)),5) =

And then you should make both fields have the same datatype and format if they are going to be used to represent the same thing so your data is a bit more normalized...



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page
   

- Advertisement -