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


TSQL


TSQL

Author
Message
Sudhirc
Sudhirc
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1603 Visits: 59
Comments posted to this topic are about the item TSQL
Hugo Kornelis
Hugo Kornelis
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18541 Visits: 12426
I knew my reply was going to be considered wrong before I submitted, but I just didn't want to submit an incorrect reply, even though I second-guessed the author's mind.

WHEN MATCHED, WHEN NOT MATCHED BY TARGET, and WHEN NOT MATCHED BY SOURCE are the three valid subclauses of a MERGE statement. Of these, only WHEN NOT MATCHED BY TARGET has an optional part, so WHEN NOT MATCHED [BY TARGET] is correct as well. (Note that the square brackets are not part of the syntax, but a signifier that the BY TARGET part can be left out).

However, the BY SOURCE part of WHEN MATCHED BY SOURCE is not optional. Which makes sense, of course, for without the BY SOURCE part it couldn't be distinguished from a WHEN NOT MATCEHD BY TARGET clause. Therefor, WHEN NOT MATCHED [BY SOURCE] is not correct, even though WHEN NOT MATCHED BY SOURCE (without the brackets) is.

Suggestion to Steve: Change the answers. Remove the square brackets in all of the answer options, and you're done. (Or, to make it even more interesting, add in an extra option for WHEN NOT MATCHED without BY xxx clause - that is of course allowed as well, since the BY TARGET part of WHEN NOT BATCHED BY TARGET is optional).


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Sudhirc
Sudhirc
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1603 Visits: 59
Hi,

Thanks for the reply. Noted your point. Will take care of this in future.

Regards,

Sudhir
Tom Brown
Tom  Brown
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: 3272 Visits: 1491
Yes you never know if the question wants totally exact answers (as some do) - or not - as in this case where WHEN NOT MATCHED BY SOURCE is the correct syntax, but the available answer is WHEN NOT MATCHED [BY SOURCE] is accepted as correct.
Steve Jones
Steve Jones
SSC Guru
SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)SSC Guru (143K reputation)

Group: Administrators
Points: 143368 Visits: 19424
Hugo,

Thanks and good seeing you last week.

Didn't think about those parts being optional when I reviewed this. I kind of glanced at it and took those to be valid options.

The answers have been changed.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Anipaul
Anipaul
SSCrazy Eights
SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)

Group: General Forum Members
Points: 9685 Visits: 1407
Nice point Hugo. Very good explanation...Smile



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