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


IFF - 1


IFF - 1

Author
Message
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17464 Visits: 7423
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?Cool

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
WWDMark
WWDMark
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1119 Visits: 530
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. :-D


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
seatedElephant
seatedElephant
SSC-Enthusiastic
SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)

Group: General Forum Members
Points: 197 Visits: 382
Nice question, thanks Ron. I went for case insensitive, but wasn't entirely sure that was the way to go.

Dave Morris Alien

"Measure twice, saw once"
sequelgarrett
sequelgarrett
Old Hand
Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)

Group: General Forum Members
Points: 337 Visits: 1248
Terrible question! Why?? Because it reminded me that I still am stuck with 2008R2. :-D

Just kidding -- but anyway, good question.
tabinsc
tabinsc
SSC Eights!
SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)

Group: General Forum Members
Points: 966 Visits: 919
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?
sequelgarrett
sequelgarrett
Old Hand
Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)

Group: General Forum Members
Points: 337 Visits: 1248
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.
tabinsc
tabinsc
SSC Eights!
SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)SSC Eights! (966 reputation)

Group: General Forum Members
Points: 966 Visits: 919
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?
Mike Dougherty-384281
Mike Dougherty-384281
SSC Eights!
SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)SSC Eights! (852 reputation)

Group: General Forum Members
Points: 852 Visits: 944
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... Smile
Primo Dang
Primo Dang
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2112 Visits: 1396
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... Smile


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.
carlje54
carlje54
Valued Member
Valued Member (64 reputation)Valued Member (64 reputation)Valued Member (64 reputation)Valued Member (64 reputation)Valued Member (64 reputation)Valued Member (64 reputation)Valued Member (64 reputation)Valued Member (64 reputation)

Group: General Forum Members
Points: 64 Visits: 93
Yes the correct answer is: it depends on which collation was selected during the install. The default is Latin1-General case-insensitive.
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