SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Conditional Order By


Conditional Order By

Author
Message
mister.magoo
mister.magoo
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10737 Visits: 7891
Comments posted to this topic are about the item Conditional Order By

MM


select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • malleswarareddy_m
    malleswarareddy_m
    SSCrazy
    SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

    Group: General Forum Members
    Points: 2757 Visits: 1189
    Non Sense question.I thought correct answer. means it will through error.but due to hint given by him i did not consider date and got wrong. am not happy with question and answer.

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)
    tommyh
    tommyh
    SSCrazy
    SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

    Group: General Forum Members
    Points: 2558 Visits: 2000
    Okay not the best question. However i wouldnt go as far to say it was nonsence. It shows that you cant mix different datatypes in a conditional order by without thinking about conversions.

    I do however dislike the

    WHEN @sortby = 'String1' THEN String2
    WHEN @sortby = 'String2' THEN String1


    part.
    Sorting by 'String1' and then using column String2 (and vice versa) doesnt really add anything. It makes you think that its a trick question. So its easy to focus on that part instead.

    So next time, no "trick" code to obscure what your trying to show ppl. Its really not needed.

    /T
    Carlo Romagnano
    Carlo Romagnano
    SSCertifiable
    SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

    Group: General Forum Members
    Points: 7563 Visits: 3399
    I should remember implicit cast using CASE clause.
    Good question. I refreshed implicit cast.
    In sql2000, it gives error also with SET @sortby='Date1'. (Syntax error converting datetime from character string.), not in sql2005.

    I run on tuttopodismo
    tommyh
    tommyh
    SSCrazy
    SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

    Group: General Forum Members
    Points: 2558 Visits: 2000
    Carlo Romagnano (11/16/2010)
    I should remember implicit cast using CASE clause.
    Good question. I refreshed implicit cast.
    In sql2000, it gives error also with SET @sortby='Date1'. (Syntax error converting datetime from character string.), not in sql2005.


    No it doesnt :-) Well its not related to it being SQL2000. Probably some language issue. Works fine on mine.

    /T
    deepak.a
    deepak.a
    Ten Centuries
    Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

    Group: General Forum Members
    Points: 1360 Visits: 863
    this is the one of the way to handle those error.

    DECLARE @sortby VARCHAR(10)
    SET @sortby='String2'

    SELECT String1, String2, Date1
    FROM (
    SELECT 'StringValue1', '2', CONVERT(datetime,'1 July 2010 00:01:00')
    UNION ALL
    SELECT 'StringValue2', '1', CONVERT(datetime,'2 July 2010 00:02:00')
    ) AS a(String1,String2,Date1)
    ORDER BY
    CASE
    WHEN @sortby = 'String1' THEN String2
    WHEN @sortby = 'String2' THEN String1
    end,
    CASE
    WHEN @sortby = 'Date1' THEN Date1
    END

    Thanks & Regards
    Deepak.A
    Carlo Romagnano
    Carlo Romagnano
    SSCertifiable
    SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

    Group: General Forum Members
    Points: 7563 Visits: 3399
    tommyh (11/16/2010)
    Carlo Romagnano (11/16/2010)
    I should remember implicit cast using CASE clause.
    Good question. I refreshed implicit cast.
    In sql2000, it gives error also with SET @sortby='Date1'. (Syntax error converting datetime from character string.), not in sql2005.


    No it doesnt :-) Well its not related to it being SQL2000. Probably some language issue. Works fine on mine.

    /T

    Also, I should remember "set language 'us_english'".:-D:-D

    I run on tuttopodismo
    Nakul Vachhrajani
    Nakul Vachhrajani
    Hall of Fame
    Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

    Group: General Forum Members
    Points: 3315 Visits: 2149
    Excellent question!
    Thank-you!

    Thanks & Regards,
    Nakul Vachhrajani.
    http://nakulvachhrajani.com
    Be courteous. Drive responsibly.

    Follow me on
    Twitter: @sqltwins
    Google Plus: +Nakul
    Richard Warr
    Richard Warr
    Hall of Fame
    Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

    Group: General Forum Members
    Points: 3322 Visits: 1991
    I thought it was an interesting question as well - currently more people have it wrong than right which shows that we can still be surprised at the "behind the scenes" antics of SQL Server.

    Please don't describe questions as "nonsense", people take taime to set them and always have good intentions when they do so. It doesn't help your case if you can't spell "nonsense" either.

    _____________________________________________________________________
    MCSA SQL Server 2012
    tommyh
    tommyh
    SSCrazy
    SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

    Group: General Forum Members
    Points: 2558 Visits: 2000
    Richard Warr (11/16/2010)
    I thought it was an interesting question as well - currently more people have it wrong than right which shows that we can still be surprised at the "behind the scenes" antics of SQL Server.

    Please don't describe questions as "nonsense", people take taime to set them and always have good intentions when they do so. It doesn't help your case if you can't spell "nonsense" either.


    I know this wasnt directed at me (i dont think so anyway)... however.

    You shouldnt complain about spelling. This is an international site and as long as you can understand what someone else writes... its okay. Perfect spelling/grammar is rare.

    Also considering your own "taime" spelling... well... mistakes happen ;-)

    /T (non native english speaker)
    Go


    Permissions

    You can't post new topics.
    You can't post topic replies.
    You can't post new polls.
    You can't post replies to polls.
    You can't edit your own topics.
    You can't delete your own topics.
    You can't edit other topics.
    You can't delete other topics.
    You can't edit your own posts.
    You can't edit other posts.
    You can't delete your own posts.
    You can't delete other posts.
    You can't post events.
    You can't edit your own events.
    You can't edit other events.
    You can't delete your own events.
    You can't delete other events.
    You can't send private messages.
    You can't send emails.
    You can read topics.
    You can't vote in polls.
    You can't upload attachments.
    You can download attachments.
    You can't post HTML code.
    You can't edit HTML code.
    You can't post IFCode.
    You can't post JavaScript.
    You can post emoticons.
    You can't post or upload images.

    Select a forum

































































































































































    SQLServerCentral


    Search