Ok, here's my problem, I'll try to explain it the best I can, it may be something really simple.
I'm working in a .NET web page to add new users into the table in SQL.
I have the main table that will be updated with the new information, this table has 2 foreign keys (ids), each one of them to different tables.
Problem comes when a new user is been added, the web page displays the descriptions for these 2 fields, but in the main table I have the id's.
How can I insert the data in one single query instead of creating first 2 queries to get the id's based on the descriptions saving them into variables, and then finally insert all values to the main table.
Example:
I want to insert: 'NameofGuy', 'Administrator' , 'CompanyX'
into TableA.
TableA fields: username,role,c ompany
but role and company are ids (int), it should look like this:
'NameofGuy', 1, 2
TableB (roles): id, roleDescription
____________1 , 'Administrator'
TableC (company): id, companyName
_______________ __1, 'CompanyW'
_______________ __2, 'CompanyX'
Hope is clear.
Any help is appreciated.
I'm working in a .NET web page to add new users into the table in SQL.
I have the main table that will be updated with the new information, this table has 2 foreign keys (ids), each one of them to different tables.
Problem comes when a new user is been added, the web page displays the descriptions for these 2 fields, but in the main table I have the id's.
How can I insert the data in one single query instead of creating first 2 queries to get the id's based on the descriptions saving them into variables, and then finally insert all values to the main table.
Example:
I want to insert: 'NameofGuy', 'Administrator' , 'CompanyX'
into TableA.
TableA fields: username,role,c ompany
but role and company are ids (int), it should look like this:
'NameofGuy', 1, 2
TableB (roles): id, roleDescription
____________1 , 'Administrator'
TableC (company): id, companyName
_______________ __1, 'CompanyW'
_______________ __2, 'CompanyX'
Hope is clear.
Any help is appreciated.
Comment