This is, probably, a really simple answer, but I am not coming up with it... Any help would be greatly appreciated:  I created a web form, to a stored procedure, that submits userID, deptID, and a string of comma separated itemID's like so. The purpose is to map an employeeID to itemID's for different departments.:  (1, 2, '20,30,90,60')   I use a Table-Valued function to split that in to a proper table like so:  EmployeeID | deptID | ItemID         1       2       20         1       2       30         1       2       90         1       2       60   I, then, perform a MERGE between a mapping table (ID, EmployeeID, DeptID, ItemID) and the table created from the splitting function before.  MERGE [dbo].[metricEmployeeDimItemDim] AS TARGET USING (SELECT accountID, deptID, ItemID FROM api.splitItemInts(@employeeId, @deptID, @ItemIDs, ',') ) AS SOURCE ON TARGET.employeeId = SOURCE.accountID AND TARGET.ItemId = SOURCE.ItemID WHEN NOT MATCHED BY TARGET THEN     INSERT (employeeID, deptID, ItemID)     VALUES (SOURCE.accountID, SOURCE.deptID, SOURCE.ItemID) WHEN NOT MATCHED BY SOURCE THEN DELETE;   The issue is that I need the merge statement to not clean out the entire TARGET table... I just need it to affect records with matching USER and DEPT ID's (syncing entries for the ItemID)  How can I accomplish this with a MERGE statement?  Thank you, Wes
I am trying to use a MERGE statement to insert or delete rows from a table, but I only want to act on a subset of those rows. The documentation for MERGE has a pretty strongly worded warning:     It is important to specify only the columns from the target table that are used for matching purposes. That is, specify columns from the target table that are compared to the corresponding column of the source table. Do not attempt to improve query performance by filtering out rows in the target table in the ON clause, such as by specifying AND NOT target_table.column_x = value. Doing so may return unexpected and incorrect results.   but this is exactly what it appears I have to do to make my MERGE work.  The data I have is a standard many-to-many join table of items to categories (e.g. which items are included in which categories) like so:  CategoryId   ItemId ==========   ====== 1            1 1            2 1            3 2            1 2            3 3            5 3            6 4            5   What I need to do is to effectively replace all rows in a specific category with a new list of items. My initial attempt to do this looks like this:  MERGE INTO CategoryItem AS TARGET USING (   SELECT ItemId FROM SomeExternalDataSource WHERE CategoryId = 2 ) AS SOURCE ON SOURCE.ItemId = TARGET.ItemId AND TARGET.CategoryId = 2 WHEN NOT MATCHED BY TARGET THEN     INSERT ( CategoryId, ItemId )     VALUES ( 2, ItemId ) WHEN NOT MATCHED BY SOURCE AND TARGET.CategoryId = 2 THEN     DELETE ;   This appears to be working in my tests, but I am doing exactly what MSDN explicitly warns me not to do. This makes me concerned that I will run into unexpected problems later on, but I cannot see any other way to make my MERGE only affect rows with the specific field value (CategoryId = 2) and ignore rows from other categories.  Is there a "more correct" way to achieve this same result? And what are the "unexpected or incorrect results" that MSDN is warning me about?
Script to determine if files are Images I would like to create a shell script that will check to make sure all files in a directory are image files.  We recently had an issue where a hacker was able to generate a file in a directory and mask it as a .jpg file. I would like to create a shell script to check all files in the directory to make sure they are real jpg, gif or png files. I have an Android device which is running Android 4.0.3 (or something like that).  My little brother decided to try and guess my lock screen pattern the other day, and ended up locking me out.   I have since been unable to log back in to the tablet using my Google Account details. I provided the correct login details, however it says they are incorrect. Could this be connected to the fact I have no internet connection?  I have no internet connection as the device is WiFi only, and the WiFi is currently turned off. I cannot turn it on, as I am locked out.  How can I log back into my tablet without wiping the user data? Retagging questions in terms of possible answer technologies When entering the title of this query I was pointed to , which has tentatively endorsed this concept, especially once an answer has been accepted.  Can I get a confirmation that it is actually good practice before an answer has been accepted? (IMHO it is not.)  Two examples:   : I didn't need a WCF answer, which I would have assumed if I had seen the question tagged with WCF even if I didn't mention it in the question or title.   : It looks probable that the answer (if there is one) is related to AOP, but the questioner does not require it. When a vehicle makes a turn, the two front wheels trace out two arcs as shown in the figure below. The wheel facing towards the inside of the turn has a steering angle that is greater than that of the outer wheel. This is necessary to ensure that both front wheels smoothly trace out two arcs, which have the same center, otherwise the front wheels will skid on the ground during the turn.   During a turn, do the rear wheels necessarily trace out the same arcs as the front wheels? How do I print all lines of a file with duplicate values in a certain column Here is what it looks like in Blender Render (Not Cycles).   This is how I set it up.   Basically, I'm trying to export it, but it's not including the &quot;Freestyle&quot; lines. When I open up the .dae file in Finder, it looks like this:   What is wrong here? I want it to be exported (COLLIDA .dae) with the black outline. I'm seeming to think that maybe the &quot;Freestyle&quot; is only for the Blender Render. Am I right? How would I go about getting the black outline included in my exported model? Is it an export setting I have to tick? Thanks for any helpful answers. How to get product recommendations In the following setup, does method B run in a (new) transaction?  An EJB, having two methods, method A and method B  public class MyEJB implements SessionBean     public void methodA() {        doImportantStuff();        methodB();        doMoreImportantStuff();     }      public void methodB() {        doDatabaseThing();     } }   The EJB is container managed, with methodB in requires_new transaction, and method A in required transaction. thus:  &lt;container-transaction id="MethodTransaction_1178709616940"&gt;   &lt;method id="MethodElement_1178709616955"&gt;     &lt;ejb-name&gt;MyName&lt;/ejb-name&gt;     &lt;method-name&gt;*&lt;/method-name&gt;   &lt;trans-attribute&gt;Required&lt;/trans-attribute&gt;   &lt;/method&gt;   &lt;method id="MethodElement_1178709616971"&gt;     &lt;ejb-name&gt;MyName&lt;/ejb-name&gt;     &lt;method-name&gt;methodB&lt;/method-name&gt;   &lt;/method&gt;   &lt;trans-attribute&gt;RequiresNew&lt;/trans-attribute&gt; &lt;/container-transaction&gt;   Now let another EJB call methodA with an EJB method call. methodA now runs in an transaction. Will the subsequent call to methodB from methodA run in the same transaction, or does it run in a new transaction? (mind, it's the actual code here. There is no explicit ejb-call to method B) Enumerate non-isomorphic graphs on n vertices In the following the graphs are assumed to be undirected and simple.  1.Enumerate the number of non-isomorphic graphs on $n$ vetrices where $n$ is fixed.  Here are some ideas I had:  The number of labeled graphs is $ 2^{\frac{n(n-1)}{2}} $.  So it is enough to find the number unlabeled graphs on $n$ vertices.I have no idea for this.  2.Enumerate the number of non-isomorphic graphs on $n$ vertices and $m$ edges where $n,m$ are fixed.   Can we find a closed formula for each of this?  Any help?   Thank you! How to remove Ubuntu and put Windows back on? I have absolutely no experience with Linux, and I desperately need to get my computer back up and running again with Windows.  How do I remove Ubuntu and reinstall Windows?    Editor's note: many of the answers are about removing Ubuntu from dual-boot but keeping Windows (which is a bit complicated), while other answers are about removing Ubuntu from single-boot (which is easy: basically just format the disk while installing Windows). The question as written is ambiguous between dual-boot or single-boot. Should I use #define, enum or const? What is the difference between test set and validation set? I found this confusing when I use the neural network toolbox in Matlab. It divided the raw data set into three parts:   training set validation set test set   I notice in many training or learning algorithm, the data is often divided into 2 parts, the training set and the test set.  My questions are:   what is the difference between validation set and test set?  Is the validation set really specific to neural network? Or it is optional. To go further, is there a difference between validation and testing in context of machine learning? What is the standard team composition for a conquest game? I'm very new to Smite, and I'm wondering if there is some kind of standard team composition in high level play, comparable to the top, jungle, mid, dual lane meta in LoL.  What are the roles, and where should they go to start the game? For what $n$ is $U_n$ cyclic? Is it really possible to break the speed of light by flicking your wrist with a laser pointer? I can do an eval("something()"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#?  An example of what I am trying to do is: I have an integer variable (say i) and I have multiple properties by the names: "Property1", "Property2", "Property3", etc. Now, I want to perform some operations on the " Propertyi " property depending on the value of i.   This is really simple with Javascript. Is there any way to do this with C#? Proving that $(3n)!$ is divisible by $n! \times (n + 1)! \times (n + 2)!$ if $n$ is greater than 2 Prove that:  If $n$ is greater than 2, then $(3n)!$ is divisible by $n! \times  (n + 1)! \times  (n + 2)!$  From Barnard &amp; Child's "Higher Algebra".  I know that the highest power of a prime $p$ contained in $N$! is  $$ \left\lfloor{\frac{N}{p}}\right\rfloor + \left\lfloor{\frac{N}{p^2}}\right\rfloor + \left\lfloor{\frac{N}{p^3}}\right\rfloor ... $$  I'm unable to show that the formula above gives a higher value for $N = 3n$ than for the sum of its values when $N$ = $n$ , $n + 1$ and $n + 2$, considering the condition that $n &gt; 2$. Is there a word for when an action has an effect opposite to the one intended? Is there a word or phrase to express the concept of an action having the opposite effect of the expected outcome?  For example, a drug taken to cure headaches that actually causes headaches, or an advertising campaign designed to deter smoking that leads to an increase in smoking. Why don't we include $\rho g h$ in a hydraulic jack below? How to reconcile the cashless human/Federation society with human traders and merchants