Filter and mutliply sql table with stored procedure

ravi kumar 331 Reputation points
2022-04-23T04:38:45.337+00:00

Hello all,

I am very new to SQL ,

I have table like this :

195784-image.png

in my winform I have two text boxes for Dish & number of persons:
so if i type Cake & 3 , the result should be like below :
195764-image.png

Pls someone guide me how to achieve the same.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,461 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
9,739 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ronen Ariely 14,636 Reputation points MVP
    2022-04-23T12:55:09.507+00:00

    Hi ravi and welcome to the QnA forums

    I am very new to SQL , I have table like this :

    First step in the right way to learn well is to learn how to ask questions :-)

    What you provide is image and not table. We cannot demonstrate execution on images. What you need to provide in each question is a DDL+DML. In short, we need queries to create the table and top insert some sample data and not images. If this answer will not cover your needs then please provide the missing information.

    in my winform I have two text boxes for Dish & number of persons: so if i type Cake & 3 , the result should be like below :

    There 2 actions which you try to do on the data from the table: (1) Filter only rows with Dish = 'Cake' and (2) You want to multiply the value in the column Qty by 3 or in other words you want to get Qty*3

    SQL language is based on English and all you need to do is to write these 2 action exactly as it sound in English, which why SQL language was designed for any child from the age that he can read and write English will be able to learn the language in a few days

    So... let's see the code

    SELECT 
        Dish,               -- this is what you want to get in the first column in the result
        Ingedient,       -- this is what you want to get in the second column in the result
        Qty*3              -- this is what you want to get in the third column in the result: Qty multiply by 3 
    FROM Table_Name
    -- And now we can add the filters
    WHERE Dish = 'Cake'
    

    You should go over a simple course online to learn SQL. It should not take more than a few days including the exercise. You can start with the tutorial: https://www.w3schools.com/sql/


0 additional answers

Sort by: Most helpful