Friday, June 17, 2011

Concatenating strings from multiple records into a single value

Say that you want to concatenate values from several records into a single string.  The classic example is a list of categories where you want to present it to the user as Category Name followed by a comma separated list of all products for that category.

There are multiple solutions for this problem, but this one seems to be the most straight forward:

   1: Select C.Name, 
   2:     stuff((select ', ' + P.Name 
   3:             from Product as P
   4:                 where P.CategoryId = C.Id
   5:             for xml path('')),1,2,'') as ProductList
   6:     from Category as C

Monday, June 13, 2011

Trouble Connecting to a Server on a Different Domain

Occasionally, when attempting to connect to a server on a different domain, you may get an error that says the credentials are incorrect even though you didn’t enter any credentials, or if you do enter the credentials, it says that these credentials conflict with an existing set of credentials.   To fix this, open a command prompt and enter the following command:

   1: net use \\server /delete

Then you should be able to connect to the server, either through the command prompt or through the command prompt:

   1: net use x: \\server\share /user:username password