-1

As the title says I want to run a select statement to return 1 value for each item searching with. I will provide a simple example for this.

Lets say that my table is the following:

table1

Mdl       Code
Model     Model Code
M1070     32HT
M1060     32A4

where table1 is the table, Mdl and Code are the columns, and there are two entries.

Now lets say that I have a list that makes it so that I need to convert from model codes to models. This list can have model codes found in table1, it can have entries not found in table1, and it can have entries that repeat in the search. My question is how (in a generalized sense since my data is more complex) can I run the following example of a search:

32HT
32HT
32HM
NULL (blank entry in searching)

I would ideally like it to return the following:

M1070
M1070
"" (a null or blank value as a place holder so the lists stay in line)
"" (a null or blank value again)

The importance of this is that the return values must always return something or the list it is being dumped into can get off.

Thanks ahead of time.

To clear some things up, the list would be a generated list (so not from an existing table). I am also using JET SQL so that limits some of the SQL functions available.

onedaywhen
  • 55,269
  • 12
  • 100
  • 138
Eric F
  • 899
  • 2
  • 21
  • 45

2 Answers2

1
SELECT l.Code, COALESCE(t.mdl, '') as mdl
    FROM List l
        LEFT JOIN table1 t
            ON l.Code = t.Code
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235
-1

Is the list coming from another table? If so, an Outer Join between the two tables should preserve the null values.

SELECT * FROM listtable
LEFT OUTER JOIN table1
Ashlin
  • 26
  • 6
  • No, the search parameters would be inputted. Sorry for the confusion – Eric F Oct 25 '11 at 20:14
  • @EricF I would recommend reviewing [this article](http://msdn.microsoft.com/en-us/library/aa173839%28v=sql.80%29.aspx) for notes on how to write data to a table, and just declare a temporary table to join your existing table with. – Ashlin Oct 25 '11 at 20:49