ironcurtain Posted August 17, 2012 Share Posted August 17, 2012 Hi Everyone, I have two tables: table1: history dayid nofile servername11082012 1 server112082012 1 server213082012 1 server314082012 1 server1* table2 servers: serverName unitserver1 emeaserver2 uaeserver3 emea I wrote a querry to join tables: select history.dayid, history.nofile, history.servername, servers.unitfrom historyleft joinserversonhistory.servername = servers.serverName In my case server1* is the same as server1but SQL see that as a different names. Is there a possibility to join the tables without empty cells?I'd like to avoid creating temporary tables. Thank You for answering my question. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 17, 2012 Share Posted August 17, 2012 If you're going to use that field as a foreign key then the values need to match what is in the other table. There's no reason for the "*" in the name. If you're using the asterisk to indicate something else about that server or record, then make that indicator another field and leave the name field as a foreign key into the other table. You can also add an entry for "server1*" to the servers table but if they are supposed to represent the same machine then it doesn't make sense to duplicate them in the table. Link to comment Share on other sites More sharing options...
ironcurtain Posted August 17, 2012 Author Share Posted August 17, 2012 I thought that maby there is some solution similar to "servers.servername like history.serverName" or there is possibility to cut of the last character in serverName.Anyway thank You for the reply. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 17, 2012 Share Posted August 17, 2012 You can use string functions to transform the value if you want to, but if that column is going to be a foreign key then it just makes sense for the data to match. I don't know what all of your data looks like, but you can remove asterisks from the name and compare the rest if you want to do that. Cutting off the last character is possible, but depending on your data that might result in false matches. Link to comment Share on other sites More sharing options...
ironcurtain Posted September 1, 2012 Author Share Posted September 1, 2012 Please close the topic. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now