If...else query in sql

sql server Poland
  • 16 years ago

    Can someone help me?
    I have this query


    Code:
    select *
    from KASTANZABEZPIECZEN as jeden
    Where data = (SELECT DISTINCT MAX(data)
    from KASTANZABEZPIECZEN  as dwa
    Where jeden.nazwastacji = dwa.nazwastacji) and dc ='0'


    I want to use If..Else for every column in my table. It contains 50 columns. I know that i must create 50 if..else.
    But how to make one? I have a criteria for returning values.


    For example:
    if firstcolumnvalue >1 then
    else firstcolumnvalue <1


    I made this


    Code:
    Use smsk3a
    select *
    from KA
    STANZABEZPIECZEN as jeden
    Where data = (SELECT DISTINCT MAX(data)
    from KA
    STANZABEZPIECZEN  as dwa
    Where jeden.nazwastacji = dwa.nazwastacji and ms = '1')
    if KA
    STANZABEZPIECZEN.auditbaseobjects = '1'
    begin
    PRINT 'The following dc are excellent mod
    cook books:'
    PRINT ' '
    select *
    from KASTANZABEZPIECZEN as jeden
    Where data = (SELECT DISTINCT MAX(data)
    from KASTANZABEZPIECZEN  as dwa
    Where jeden.nazwastacji = dwa.nazwastacji and dc = '1')
    End
    else
    if KASTANZABEZPIECZEN.auditbaseobjects = '0'
    begin
    select *
    from KASTANZABEZPIECZEN as jeden
    Where data = (SELECT DISTINCT MAX(data)
    from KASTANZABEZPIECZEN  as dwa
    Where jeden.nazwastacji = dwa.nazwastacji and ms = '1')
    end


    smsk3a is the name of database, KAStan_Zabezpieczen is the name of table and DC, nazwastacji and auditbaseobjects are the names of columns.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“You can stand on the shoulders of giants OR a big enough pile of dwarfs, works either way.”