locked
Adding variable value based on counting number in Sql server query RRS feed

  • Question

  • User1623409651 posted

    Hi,

    I want to add the variable values based on counting number in sql server query

    Suppose I have variable value = 40 and count number = 3 then result will be

    40+ 40+40 = 120

    Basically counting number is dynamic

    suggest the way

    Regards,

    Friday, April 26, 2019 5:20 AM

Answers

  • User-893317190 posted

    Hi Rameezwaheed,

    Not sure about your requirement.

    Seems you want to get value*number, then declare a variable value and a variable number.

     declare @value int;
     declare @number int;
     set @value=40;
     set @number =3;
     select @value*@number

    If this is not your case , please show your data in  table and your desired result.

    Maybe you need case keyword in sqlquery.

    https://www.w3schools.com/sql/sql_case.asp

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 26, 2019 8:02 AM

All replies

  • User-893317190 posted

    Hi Rameezwaheed,

    Not sure about your requirement.

    Seems you want to get value*number, then declare a variable value and a variable number.

     declare @value int;
     declare @number int;
     set @value=40;
     set @number =3;
     select @value*@number

    If this is not your case , please show your data in  table and your desired result.

    Maybe you need case keyword in sqlquery.

    https://www.w3schools.com/sql/sql_case.asp

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 26, 2019 8:02 AM
  • User-1716253493 posted

    SELECT @var * count(*) ...

    Saturday, April 27, 2019 7:11 AM