2
Answers

Create a procedure that produce matching data sets

Photo of peter

peter

2y
632
1

At present i have the following query. Which produce whole result set of both vehicle Make and Models. I now wish to return only unique Makes of all vehicles initially and when item selected in listview return both list of Makes and corresponding Models 

Result

Make     Ford

Make     Toyota

Make     Honda

Model    Focus

Model    Fiesta


                selectCommand = "SELECT distinct MAKE, MODEL,MODEL_ID,MAKE_ID FROM vehicle_sellor where newvehicle='" & DDL.SelectedValue & "'"

           Note: the where clause here should return all row when DDL.SelectedValue =""

at present it does not!

Also should introduce another where statement for selected Make that returns corresponding Models.

Answers (2)

0
Photo of peter
NA 320 0 2y
i see your point of view.
I do have a relational table of vehicle Make and Models though that is only for selecting the vehicles.
After selection i insert records into a flat file table. The relationships between Make and Model can be drawn from MakeID column. It makes it awkward if i had to insert selected records into two separate tables when one does nicely. I now would like to build a stored procedure that will list all Makes and Makeid values and also list Models that relate to selected Make. At moment i return all makes and related models. 
0
Photo of Nitin Sontakke
136 13.6k 15.3k 2y
You will need to write a separate query for each level of granularity of data (and in the process, ignore other data attributes depending on need / situation). That is the nature of relational data anyway.
 
Furthermore, if you already have successfully implemented normalization, you should typically have separate table exclusively dedicated for the Makes.
 
In that case, you don't really need a DISTINCT clause, instead you will SELECT all rows from that table, which are by nature DISTINCT.
 
If not, your above query is good but just remove all other unwanted columns for the purpose of first result set.
 
Please be generally aware that you will not be able to hit two birds in one stone.