Dumb SQL Server Query question
Date: 12/01/05
(Asp Dot Net) Keywords: database, sql
I'm writing a program that does queries on a database, and we just converted to a code-table format (instead of whole strings going in the DB we just put in numbers that reference another table which has all the definitions. Note that these tables are NOT connected (sadly.)) Anyways I'm writing this program that returns data from the database into a datagridview. I've been told that I can't do the conversion on the DataSet or the DGV side and that SQL server needs to do it, so basically I need to write a query that will get all the records that match the request, and then in a particular column, instead of putting in the number that is in teh database, have it look at the code table, find the matching id, and have THAT be displayed instead.
Here's conceptually what I'm going for (this is NOT SQL compliant and my SQL knowledge isn't that great. Hell if it was I wouldn't be here asking this question which I know any standard SQL DB user will likely know the answer to):
SELECT * FROM Table1, Table2
In Table1.Column,
instead of showing the code in it,
WHERE Table1.Column = Table2.Column(id),
Display in Table1.Column the info in Table2.Description.
I realize this is sort of hard to describe in text vs speech. I know there's an easy way to do this with an Inner Join, but that simply adds the info from the 2nd table to the end of the first (and displayed) table.
Here's the SQL code
SELECT * FROM sfrf_request
INNER JOIN sfrf_request_type
ON CONVERT(int,sfrf_request.request_type)=sfrf_request_type.id
WHERE sfrf_request.id = ddl1.SelectedIndex
BTW the CONVERT function is used because the column has string data in it still and thus I can't reference it as an integer.
Any help would be greatly appreciated.
Source: http://community.livejournal.com/aspdotnet/49681.html