SQL Query

  • Guys,

    I have a database contains 3 fields for a Price as:

    ProdName , MinPrc and MaxPrc.

    Now i want to write a search query for:

    When i enter the price in the textbox it should return the product name.

    For eg:

    ProdName MinPrc MaxPrc

    Apple 10 15

    Orange 10 20

    grapes 12 30

    Now i enter a price 12, so output should return all the rows which satisfies the value.

    Thank you in advance.

  • khandaresarang (10/24/2016)


    Guys,

    I have a database contains 3 fields for a Price as:

    ProdName , MinPrc and MaxPrc.

    Now i want to write a search query for:

    When i enter the price in the textbox it should return the product name.

    For eg:

    ProdName MinPrc MaxPrc

    Apple 10 15

    Orange 10 20

    grapes 12 30

    Now i enter a price 12, so output should return all the rows which satisfies the value.

    Thank you in advance.

    So what's the question? In whatever you're using for your front end, put a text box on the screen and when it changes, query the rows you need. Write them to whatever interface you have and you're done.

  • Quick suggestion for the SQL part of your problem

    😎

    USE TEEST;

    GO

    SET NOCOUNT ON;

    DECLARE @SEEK_PRICE INT = 12

    ;WITH SAMPLE_DATA (ProdName,MinPrc,MaxPrc) AS

    (

    SELECT 'Apple' , 10, 15 UNION ALL

    SELECT 'Orange', 10, 20 UNION ALL

    SELECT 'grapes', 12, 30

    )

    SELECT

    SD.ProdName

    ,SD.MinPrc

    ,SD.MaxPrc

    FROM SAMPLE_DATA SD

    WHERE @SEEK_PRICE BETWEEN SD.MinPrc AND SD.MaxPrc;

    Output

    ProdName MinPrc MaxPrc

    -------- ----------- -----------

    Apple 10 15

    Orange 10 20

    grapes 12 30

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply