footboyedit Posted February 3, 2016 at 04:35 PM Report Share #593066 Posted February 3, 2016 at 04:35 PM (edited) Boa tarde, tou a fazer uma aplicação onde tenho que ter uma combobox que receba um nome que na tabela em que estou (sql server) está abreviado. Portanto na combobox tem que aparecer o nome COMPLETO que está associado a essa abreviatura mas que está noutra tabela. O que faço para ir buscar esse nome completo? Obrigado 🙂 Edited February 3, 2016 at 04:51 PM by footboyedit Link to comment Share on other sites More sharing options...
AJBM Posted February 3, 2016 at 05:44 PM Report Share #593070 Posted February 3, 2016 at 05:44 PM Boas! Consegues fazer uma query que apresente abreviatura e o respetivo nome completo? Link to comment Share on other sites More sharing options...
footboyedit Posted February 3, 2016 at 06:03 PM Author Report Share #593071 Posted February 3, 2016 at 06:03 PM (edited) Sim, o problema está na ligação entre as duas tabelas. Tenho uma tabela independente só para o Nome Completo e Abreviatura. Eu quero que a abreviatura que está na tabela principal que associe ao nome comoleto que está na outra. Edited February 3, 2016 at 06:12 PM by footboyedit Link to comment Share on other sites More sharing options...
AJBM Posted February 3, 2016 at 06:13 PM Report Share #593072 Posted February 3, 2016 at 06:13 PM Não percebi, se consegues fazer uma query que apresente abreviatura e o respetivo nome completo. Qual é o problema na ligação entre as duas tabelas? Podes apresentar o que tens. Link to comment Share on other sites More sharing options...
footboyedit Posted February 3, 2016 at 06:19 PM Author Report Share #593073 Posted February 3, 2016 at 06:19 PM (edited) Tenho dados de funcionarios na tabela principal. Um dos campos é o número de laboratorio (que está abreviado). Eu queria mostrar esse dado numa textbox mas mostrando ao invés da abreviatura o nome completo que está associado à abreviatura na outra tabela. Edited February 3, 2016 at 06:23 PM by footboyedit Link to comment Share on other sites More sharing options...
footboyedit Posted February 4, 2016 at 09:07 AM Author Report Share #593083 Posted February 4, 2016 at 09:07 AM alguem? 🙂 Link to comment Share on other sites More sharing options...
Retsu9 Posted February 4, 2016 at 09:12 AM Report Share #593084 Posted February 4, 2016 at 09:12 AM (edited) ok nao estou a perceber o teu problema nem como tens as coisas mas supondo que tens isto: tabela1: tem um que tem 1 chave primária , por exemplo 'codigo', abreviatura, e nome_completo. tabela2: entre outras coisas, tens um campo associado ao campo 'codigo' da tabela1 query="Select nome_completo From tabela1, tabela2 Where tabela2.codigo=tabela1.codigo" Edited February 4, 2016 at 09:31 AM by Retsu9 Link to comment Share on other sites More sharing options...
tiago.f Posted February 4, 2016 at 09:24 AM Report Share #593085 Posted February 4, 2016 at 09:24 AM (edited) Esqueceste-te da tabela2 no FROM 🙂 Footboy le isto: http://www.w3schools.com/sql/sql_join.asp Edited February 4, 2016 at 09:25 AM by tiago.f Link to comment Share on other sites More sharing options...
Retsu9 Posted February 4, 2016 at 09:31 AM Report Share #593087 Posted February 4, 2016 at 09:31 AM Esqueceste-te da tabela2 no FROM 🙂 Footboy le isto: http://www.w3schools.com/sql/sql_join.asp ya fois foi vou edit , obrigado 😉 Link to comment Share on other sites More sharing options...
footboyedit Posted February 4, 2016 at 10:36 AM Author Report Share #593093 Posted February 4, 2016 at 10:36 AM (edited) ok nao estou a perceber o teu problema nem como tens as coisas mas supondo que tens isto: tabela1: tem um que tem 1 chave primária , por exemplo 'codigo', abreviatura, e nome_completo. tabela2: entre outras coisas, tens um campo associado ao campo 'codigo' da tabela1 query="Select nome_completo From tabela1, tabela2 Where tabela2.codigo=tabela1.codigo" O problema é que não tenho nome_completo na primeira tabela. E no where no tabela2.codigo está a dar no sql server "The multi-part identifier "tabela2.codigo" could not be bound. " Edited February 4, 2016 at 10:37 AM by footboyedit Link to comment Share on other sites More sharing options...
Retsu9 Posted February 4, 2016 at 10:38 AM Report Share #593095 Posted February 4, 2016 at 10:38 AM tens de usar os campos da tua tabela... mostra como tens as tuas tabelas Link to comment Share on other sites More sharing options...
footboyedit Posted February 4, 2016 at 10:39 AM Author Report Share #593096 Posted February 4, 2016 at 10:39 AM (edited) sim eu sei... estao exatamente assim isso é o problema Edited February 4, 2016 at 10:39 AM by footboyedit Link to comment Share on other sites More sharing options...
Retsu9 Posted February 4, 2016 at 10:41 AM Report Share #593097 Posted February 4, 2016 at 10:41 AM se tu tens 2 tabelas completamente independentes nao podes fazer nada.... nesse caso teras de ter 2 tabelas relacionadas..seria mais facil se mostrares como tens as tabelas..... Link to comment Share on other sites More sharing options...
footboyedit Posted February 4, 2016 at 11:27 AM Author Report Share #593103 Posted February 4, 2016 at 11:27 AM como relaciono 2 tabelas? Link to comment Share on other sites More sharing options...
tiago.f Posted February 4, 2016 at 11:28 AM Report Share #593105 Posted February 4, 2016 at 11:28 AM http://www.w3schools.com/sql/sql_join.asp Link to comment Share on other sites More sharing options...
footboyedit Posted February 4, 2016 at 11:35 AM Author Report Share #593106 Posted February 4, 2016 at 11:35 AM e coloco o inner join na mesma query certo? Link to comment Share on other sites More sharing options...
Retsu9 Posted February 4, 2016 at 11:42 AM Report Share #593108 Posted February 4, 2016 at 11:42 AM eu penso que o que tu queres é algo do genero, vou dar um exemplo diferente. tabela: funcionarios Campos: ID_func, ID_funcao, Nome tabela: funcoes Campos: ID_funcao, Descricao ora se eu fizer select a tabela funcionarios , aparece me algo do genero: 1,2,Ricardo. mas eu em vez do id da funçao quero mostrar a descriçao da mesma, entao fazes: Select * From funcionarios INNER JOIN funcoes ON funcionarios.ID_Funcao=funcoes.ID_funcao Link to comment Share on other sites More sharing options...
footboyedit Posted February 4, 2016 at 12:01 PM Author Report Share #593113 Posted February 4, 2016 at 12:01 PM (edited) eu penso que o que tu queres é algo do genero, vou dar um exemplo diferente. tabela: funcionarios Campos: ID_func, ID_funcao, Nome tabela: funcoes Campos: ID_funcao, Descricao ora se eu fizer select a tabela funcionarios , aparece me algo do genero: 1,2,Ricardo. mas eu em vez do id da funçao quero mostrar a descriçao da mesma, entao fazes: Select * From funcionarios INNER JOIN funcoes ON funcionarios.ID_Funcao=funcoes.ID_funcao Ok, acho que é isso. Agora como coloco a descricao aparecer diretamente numa combobox quando seleciono o funcionario que esta noutra combobox? Edited February 4, 2016 at 12:03 PM by footboyedit Link to comment Share on other sites More sharing options...
Retsu9 Posted February 4, 2016 at 12:11 PM Report Share #593115 Posted February 4, 2016 at 12:11 PM (edited) Ok, acho que é isso. Agora como coloco a descricao aparecer diretamente numa combobox quando seleciono o funcionario que esta noutra combobox? "Select * From funcionarios INNER JOIN funcoes ON funcionarios.ID_Funcao=funcoes.ID_funcao Where ID_func=comboboxitem" caso tenhas acesso ao id do funcionario senao pelo nome, mas pelo nome pode haver repetiçoes e escreves o campo Descricao da tabela funcoes, Edited February 4, 2016 at 12:13 PM by Retsu9 Link to comment Share on other sites More sharing options...
footboyedit Posted February 4, 2016 at 12:20 PM Author Report Share #593116 Posted February 4, 2016 at 12:20 PM (edited) "Select * From funcionarios INNER JOIN funcoes ON funcionarios.ID_Funcao=funcoes.ID_funcao Where ID_func=comboboxitem" caso tenhas acesso ao id do funcionario senao pelo nome, mas pelo nome pode haver repetiçoes e escreves o campo Descricao da tabela funcoes, Não entendi a parte do "comboboxitem". Escrevo Descricao onde? Como chamo a Descricao para a combox assim que seleciono o funcionario? Edited February 4, 2016 at 12:24 PM by footboyedit 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