Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12345»»»

IFF - 1 Expand / Collapse
Author
Message
Posted Thursday, June 6, 2013 3:57 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 7:27 AM
Points: 3,864, Visits: 5,008
Interesting question, thanks Ron

The fact that SQL2012 now supports all these Access and/or Excel functions is a bit disturbing - making the writing of T-SQL easier for those who migrate from Access to SQL Server, but keeping the poor performing queries the same?


____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #1460601
Posted Thursday, June 6, 2013 4:33 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Thursday, July 10, 2014 3:22 AM
Points: 642, Visits: 518
I was wondering about the collation issue (i.e. case sensitive or not) and as the question didn't specify the collation I took a punt...... and got it wrong! Hey Ho.


MCITP
MCTS - E-Business Card
Twitter: WWDMark

Try not! Do or do not, there is no try

email: info@weekendwebdesign.co.uk
Personal Website: www.markallen-online.co.uk
Business Website: www.weekendwebdesign.co.uk
Post #1460608
Posted Thursday, June 6, 2013 5:49 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, July 10, 2014 9:51 AM
Points: 88, Visits: 319
Nice question, thanks Ron. I went for case insensitive, but wasn't entirely sure that was the way to go.


Dave Morris

"Measure twice, saw once"
Post #1460631
Posted Thursday, June 6, 2013 5:57 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 3:06 PM
Points: 77, Visits: 568
Terrible question! Why?? Because it reminded me that I still am stuck with 2008R2.

Just kidding -- but anyway, good question.
Post #1460636
Posted Thursday, June 6, 2013 6:11 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: 2 days ago @ 12:43 PM
Points: 557, Visits: 726
2008R1 tells me:
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '='.

It doesn't appear to like the @a = @b.


Tony
------------------------------------
Are you suggesting coconuts migrate?
Post #1460643
Posted Thursday, June 6, 2013 6:13 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 3:06 PM
Points: 77, Visits: 568
tabinsc (6/6/2013)
2008R1 tells me:
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '='.

It doesn't appear to like the @a = @b.


IIF isn't supported in 2008, it's new to 2012. That's why you're getting an error.
Post #1460645
Posted Thursday, June 6, 2013 7:52 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: 2 days ago @ 12:43 PM
Points: 557, Visits: 726
ggeier (6/6/2013)
tabinsc (6/6/2013)
2008R1 tells me:
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '='.

It doesn't appear to like the @a = @b.


IIF isn't supported in 2008, it's new to 2012. That's why you're getting an error.


I figured as much; I just expected to see a different error. This error looks more like IIF is not the problem but the IIF syntax is. No big deal.


Tony
------------------------------------
Are you suggesting coconuts migrate?
Post #1460701
Posted Thursday, June 6, 2013 7:54 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, June 26, 2014 7:28 AM
Points: 257, Visits: 902
Why is this question about IIF broken because of the case sensitivity issue?

What real code would ever use varchar(1)?

Was the extra space in the varchar(4) field supposed to be a trickery?

Is there a situation where this special notation of a CASE is better?

Is this feature implemented in a way that we'll later be talking about the price to pay for using this shortcut instead of writing out the case? Of course we shouldn't, but the QotD(s) around "IsNull vs Coalesce" seem to be evergreen... :)
Post #1460703
Posted Thursday, June 6, 2013 8:55 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 7:53 AM
Points: 1,723, Visits: 1,199
Mike Dougherty-384281 (6/6/2013)
Why is this question about IIF broken because of the case sensitivity issue?

What real code would ever use varchar(1)?

Was the extra space in the varchar(4) field supposed to be a trickery?

Is there a situation where this special notation of a CASE is better?

Is this feature implemented in a way that we'll later be talking about the price to pay for using this shortcut instead of writing out the case? Of course we shouldn't, but the QotD(s) around "IsNull vs Coalesce" seem to be evergreen... :)


The answer to these and other questions right here, on the next episode of QotD!

Seriously though, varchar(1) really doesn't make much sense to me, I guess char(1) would do the job perfectly and avoid the extra 2 byte overhead.

I think the extra space was indeed a trickery to lure people into assuming string comparison takes trailing spaces into consideration.

I haven't found any comparisons between IIF and CASE, but I'm guessing the performance must be very similar, and IIF is only useful to type a little less than a case expression, but only when you have one case possibility and one else possibility (unless you want to nest IIFs, which I think wouldn't make any sense).

As far as I know, difference between ISNULL and COALESCE rests solely on type definition (considering the first argument vs. type precedence across all arguments), not on performance. Seems like IIF and CASE handle this in the same way: the value returned is always converted to the most prevalent type across both (or all, when using CASE) values.
Post #1460735
Posted Thursday, June 6, 2013 8:55 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 5:43 AM
Points: 11, Visits: 30
Yes the correct answer is: it depends on which collation was selected during the install. The default is Latin1-General case-insensitive.
Post #1460736
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse