if else statment in sybase

Posted on 2008-11-17
Last Modified: 2012-05-05

I am trying to write an if - else statement where the table Machine has PROD and CPU columns.  I want to write it such that if PROD = 'Y' then insert the number of cpu in CPU column to another temporary table call #CpuCount, then sum up the number.  Can anyone please help me out ?  The table is in Sybase.  Thanks.
Question by:Kaydensun
    LVL 10

    Accepted Solution

    Not sure where the IF would come in?

    Assuming #cpuCount already exists and you want to include any data in there in your sum:

    insert #cpuCount select CPU from Machine where PROD = 'Y'
    select sum(CPU) from #cpuCount

    Assuming #cpuCount doesn't exist:

    select CPU into #cpuCount from Machine where PROD = 'Y'
    select sum(CPU) from #cpuCount

    Author Closing Comment

    Thank you for you solution.  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi ( had suggested a “sed” way, I actually shell …
    As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now