Home > Enterprise >  How to assign values from sql table which is stored vertically?
How to assign values from sql table which is stored vertically?

Time:11-20

I have been checking many other similar questions but I couldn't find an answer. I have a situation where I need to show UI a Grid whose values will be pull out from a vertical data table.

For instance, let's say, In the UI I have to show a grid like below based on the P_ID from database product table

Product name IsLaunched Exp_Price
AC1 1 4000
AC2 0 3000
AC3 0 3000

The values in the Grid will be populated from Database , which is stored in the product table like below:

P_ID Product name IsLaunched Exp_Price
1 LCD TV 1 2000
1 LED TV 1 2000
2 AC1 1 4000
2 AC2 0 3000
2 AC3 0 3000

so if I select 2 from the drop-down , the result grid should show all the products which have the p_id as 2.

CodePudding user response:

Example query that results with the data of your example

select P_ID, `Product name`, IsLaunched, Exp_Price
from product
where P_ID = 2

So far, so good. Now, we need to make sure that we dynamically receive the value set in the dropdown. That means that on the UI some event happens that changes a value. If you are working on a web app, then this will probably be a request parameter that your server-side will need to handle. If it's a desktop application, then the backend of the application needs to handle the event. Anyway, depending on the application stack you use, you will need to process the value, build a parameterized query where you pass the chosen ID (and protect against SQL injection shenanigans) to a query executor, which will ultimately run the query and return the results.

  • Related