Simple Query I Need.....

  • Hi All,

    Please anyone help me for this.

    In my table i have a column named as SID

    and Values like this...

    SID

    ----

    1

    2

    3

    4

    5

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

    I need a Query which can give the multiply of Sid Column

    Like 1*2*3*4*5

    The Result Should be 120 as Result Column

    Result

    -----

    120

    the result should be this format....

    NB: Query should be Only Select Statement..

    Cheers!

    Sandy.

    --

  • Actually, this looks like a standard "factorial" homework problem. What do you need this for?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Hi Jeff,

    Its one of the requirement,

    Is it possible by using single Query....??

    I am using TSQL for this by

    taking Temp table and Going row by row....

    So Any Idea..

    Cheers!

    Sandy.

    --

  • Jeff,

    Where is Grant....???

    😉

    Cheer!

    Sandy.

    --

  • Answer the question, Sandy... what do you need this for? "Its one of the requirement" isn't an answer. It's homework, isn't it?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Sandy,

    Why do you need this particular code? It seems like homework.

    Here is a hint.

    You should use the sum of log(sid) and natural logarithm 2.71828182845905 (sql has built in function for this)

  • Jeff,

    he he he..lolz...:P ....

    Now you will tell me....hee hee ..in my shop.....;)

    Please Tell me the Answer,

    Jeff, Is it possible or Not?

    Please ....

    Cheers!

    Sandy.

    --

  • Hey Adams,

    Can you please write the Sql query for this?

    :w00t::hehe::cool:

    Cheers!

    Sandy.

    --

  • Sandy (1/17/2008)


    Jeff,

    he he he..lolz...:P ....

    Now you will tell me....hee hee ..in my shop.....;)

    Please Tell me the Answer,

    Jeff, Is it possible or Not?

    Please ....

    Cheers!

    Sandy.

    Heh... in my shop, I tell people to do their own homework. 😉

    And, to answer your question, yes, it is possible... that's why they give the problem as homework... to see if you've been paying attention. 😛

    Please do your own homework. :w00t:

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff,

    Clearly Cheating.....;)!!!

    Jeff, I already did it by using Dynamic TSQL,

    but how can it possible in One single Select Query?

    Ok, Let me try today evening ...

    if not you will give the answer tomorrow..

    Ok..

    But Jeff, Please look to my another Post,

    its important for me...

    Waiting for ur suggestion.....

    Thanks

    Cheers!

    Sandy.

    --

  • What other post? Post the URL so I don't have to look for it. 😉

    On the homework, the method that Adam is leaning towards is not the method your instructor wants you to use. It's easy with the formula that Adam is implying... not so easy with the method your instructor wants you to use... but it's meant to teach you a little bit about some of the new functions WITH SQL Server 2005.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Hi Sandy,

    Try out this ....

    SELECT EXP(SUM(LOG(SID))) FROM #t

    😛

  • sqluser (1/17/2008)


    Hi Sandy,

    Try out this ....

    SELECT EXP(SUM(LOG(SID))) FROM #t

    😛

    Man, some people just don't get it... Who's goin' for the "A"... YOU?

    Although that's a better answer in the software world, I guarantee that's not the answer Sandy's instructor is looking for... and Sandy learned nothing about what Sandy was supposed to learn... except how to cheat. Great job, Pal!

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Hey sqluser,

    Thanks, It is working...

    Jeff,

    Actually I asked about this post...

    " http://www.sqlservercentral.com/Forums/Topic444141-338-1.aspx "

    Jeff,

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

    Sandy learned nothing about what Sandy was supposed to learn... except how to cheat. Great job, Pal!

    he he he...lolz:hehe:

    Cheers!

    Sandy.

    --

  • Create a function that calculate these values and call that function thru select query

Viewing 15 posts - 1 through 15 (of 23 total)

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