I need help with a dynamic pivot query. I would like to modify the column name (alias) but I can't get it done in the pivot. Please help. The query itself works perfectly but the username contains the domain\username format. I am trying to drop the "domain\" portion. I cannot control what is in or inserted in the database nor can I make any structure changes. I have tried "replace(x,'domain\','') but again, I can't get it to work in the pivot.  Here is what I have data table:  requestID dateClosed              closedby --------- ----------------------- ----------- 1         2016-06-12 10:34:09.000 DOMAIN\Joe 2         2016-06-12 23:35:09.000 DOMAIN\Bill 3         2016-06-12 08:02:09.000 DOMAIN\Matt 4         2016-06-13 21:46:09.000 DOMAIN\Joe 5         2016-06-13 17:34:09.000 DOMAIN\Bill 6         2016-06-14 16:39:09.000 DOMAIN\Matt 7         2016-06-14 12:38:09.000 DOMAIN\Joe 8         2016-06-14 12:37:09.000 DOMAIN\Bill 9         2016-06-15 11:36:09.000 DOMAIN\Matt 10        2016-06-16 10:35:09.000 DOMAIN\Joe 11        2016-06-13 10:35:09.000 DOMAIN\Bill 12        2016-06-15 21:46:09.000 DOMAIN\Joe 13        2016-06-15 21:47:09.000 DOMAIN\Joe 14        2016-06-15 21:48:09.000 DOMAIN\Joe   Here is my ouput after PIVOT  date                    DOMAIN\Bill DOMAIN\Joe  DOMAIN\Matt ----------------------- ----------- ----------- ----------- 2016-06-12 00:00:00.000 1           1           1 2016-06-13 00:00:00.000 2           1           0 2016-06-14 00:00:00.000 1           1           1 2016-06-15 00:00:00.000 0           3           1 2016-06-16 00:00:00.000 0           1           0   I need to remove the "Domain\" portion from the column alias. Replace() didn't work for me. SQl v2012  Here is my query  --dynamic pivot declare @cols as nvarchar(max),     @query as nvarchar(max)  set @colS = STUFF((SELECT DISTINCT ',' + QUOTENAME(r.closedby)     from MYRequests r     where r.dateclosed &gt; getdate()-30     for XML path(''), type     ).value('.','NVARCHAR(MAX)'),1,1,'')  SET @QUERY = 'select * from (     select      DateAdd(Day, DateDiff(Day, 0, dateclosed), 0) as [date],     closedby     from MyRequests     where DateAdd(Day, DateDiff(Day, 0, dateclosed), 0) &gt; getdate()-30     )     as s PIVOT     (count(closedby) for [closedby] in       ('+ @cols + '))     as PVT '  execute(@query)   Here is sample filler data:  create table MYRequests     ([requestID] smallint,     [dateClosed] datetime,     [closedby] varchar(50));  Insert into MyRequests     ([requestID], [dateclosed], [closedby]) values     (1,'20160612 10:34:09 AM','DOMAIN\Joe'),     (2,'20160612 11:35:09 PM','DOMAIN\Bill'),     (3,'20160612 08:02:09 AM','DOMAIN\Matt'),     (4,'20160613 09:46:09 PM','DOMAIN\Joe'),     (5,'20160613 05:34:09 PM','DOMAIN\Bill'),     (6,'20160614 04:39:09 PM','DOMAIN\Matt'),     (7,'20160614 12:38:09 PM','DOMAIN\Joe'),     (8,'20160614 12:37:09 PM','DOMAIN\Bill'),     (9,'20160615 11:36:09 AM','DOMAIN\Matt'),     (10,'20160616 10:35:09 AM','DOMAIN\Joe'),     (11,'20160613 10:35:09 AM','DOMAIN\Bill'),     (12,'20160615 09:46:09 PM','DOMAIN\Joe'),     (13,'20160615 09:47:09 PM','DOMAIN\Joe'),     (14,'20160615 09:48:09 PM','DOMAIN\Joe')      select * from myrequests   Please help.
I have a table to store StudentID, SubjectID, ObtainedMarks. Now I have to create a pivot table to show studentID and obtainedMarks in different subject. Number of subject may differ. I could generate pivot table for fixed subjectID like    SELECT * FROM (SELECT StudentID, SubjectID, ObtainedMarks from [Exam].[ObtainedMarkEntry]) as InvoiceResult PIVOT (     sum(ObtainedMarks) for [SubjectID] in  ([1],[2],[3],[4]) )as finalResult   This works but problem is 1,2,3 is not static it should come from same table   So I did something like   declare @minvalue int, @maxvalue int declare @myArray varchar(max) set @MyArray=''  select RowID=IDENTITY(int, 1,1), SubjectID into #tempSubject from [Exam].[ObtainedMarkEntry] select * from #tempSubject set @minvalue = (select min(RowID) from #tempSubject) set @maxvalue = (select max(RowID) from #tempSubject) while (@minvalue&lt;=@maxvalue) begin     declare @sid nvarchar(10)     set @sid=(select SubjectID from #tempSubject where RowID=@minvalue)     set @myArray= @myArray + '[' + @sid + '], '      set @minvalue= @minvalue+1 end set @myArray= SUBSTRING(@myArray,0,len(@myArray)) drop table #tempSubject  declare @q as nvarchar(max) SELECT * FROM (SELECT StudentID, SubjectID, ObtainedMarks  from [Exam].[ObtainedMarkEntry]) as InvoiceResult PIVOT (     sum(ObtainedMarks) for [SubjectID] in  (@myArray) )as finalResult   Now I am getting error at in(@myArray) can't I assign variable in this section.
How can I reliably and accurately identify the passive voice in writing or speech? I'm not interested in advice about whether or not to use it yet... I just want to know for sure what it is, so that I don't look as stupid as . "compare with" or "compare to" Please check both sentences and let me know, which one is correct and why?   She compares me with her boyfriend.  She compares me to her boyfriend. What happens when you target a "magical effect" with Dispel Magic? How to use a decimal range() step value? Is there a way to step between 0 and 1 by 0.1?   I thought I could do it like the following, but it failed:  for i in range(0, 1, 0.1):     print i   Instead, it says that the step argument cannot be zero, which I did not expect. Should words be capitalized for being religious terms? While googling about whether "atheist" should be capitalized, and skimming past posts by people blogging about atheism rather than about English grammar, I came across    It says     [Capitalize] Religions and religious terms       Examples:      Catholicism, Hinduism, Buddha, the Bible, Christian, the Ten   Commandments, Baptist church, Mt. Zion Methodist Church      NOTE: Do not capitalize the following:       Examples:      church, communion, atheist, agnostic, spirituality   but I don't recall hearing of such a prescription before. Wouldn't most of the examples listed be capitalized because they're proper nouns? Are there good examples of words being capitalized solely because they're religious terms?  I'm mainly interested in modern English, rather than days of past where a lot more words were capitalized than they are nowadays.  Somewhat related:  - use "God" when referring to the name of the god of Judaism and Christianity (a proper noun), but "god" when referring to the general concept of a deity (common noun). What is a magic number, and why is it bad? What is a magic number?  Why should it be avoided?  Are there cases where it's appropriate? Linear regression prediction interval How can I solve this functional equation, where $x,y$ are any real numbers and $f:\mathbb{R}\to \mathbb R$ is a function such that : $$f(x+y)+f(x-y)=2f(x)\cos y$$    I tried substituting $x=0$ to get $f(y)+f(-y)=2f(0)\cos y$ . Taking $x=y$ gives $f(2x)+f(0)=2f(x)\cos x$. I similar get some more relations like that, but its not really helping me in finding anything useful. I also think the function must either be $\sin$ or $\cos$ looking at the product to sum formulae. Can anyone tell me how should I solve this? Probability question of hats Why is menstruation in wild animals not a disadvantage to organismal survival? When I watch wilderness specials for more than a few minutes, I notice a familiar pattern: predators are depicted as being alerted by the scent of blood. Wounded animals seem to make the best prey and predators seem to have a heightened awareness for the smell of blood.   It would seem that it would then be a disadvantage to evolutionary survival for female organisms to menstruate. How do females of a species not attract predators to the signal of menstrual blood?   Do female organisms in the wild actually menstruate? If so, is there a difference in the composition of menses that does not alert predators? How would this not at the very least give predators an idea of the general vicinity of the female?  If wild animals excrete their menses, do they have ways in which they are able to mask the evidence of its release or are they somehow internalizing the tissue so that they are not released?  If female organisms in the wild do menstruate, then why is this not a survival disadvantage? Guess the formula for $\sum\frac 1{(4n-3)(4n+1)}$ and prove by induction How to set a domain to ip address? You can reach this IP address  (if my computer is online). I want to assign a domain to it so I wonder how is that possible when I have no DNS? I do own my domain which is ".com". My IP is static.  Thanks Eigenvalues and power of a matrix The cardinality of a language over a set of variables $V$ with $\#V= κ$ In predicate logic, to define a language, we consider the following $3$ sets:  (1) $V$, the set of variables;  (2) $F$, the sets of function symbols;  (3) $P$, the set of predicate symbols with their arities.   Now I am concidering about determine the cardinality of a language over a set with arbitary cardinality, $κ$(Note that $κ$ can be either finite, countablely infinite or uncountablely infinite ).  May I please ask:  If the cardinality of $V$, $\#V = κ$, what conditions on $V$ , $F$ and $P$ will give us a language over $V$, $F$ and $P$ with cardinality $κ$?  And may I please ask if it is the fact that if $\kappa$ is finite, then to get a language with cardinality $\kappa$ we need $(V+F+P)^{&lt;\omega}=(\kappa+F+P)^{&lt;\omega}=\kappa$, so we can never have a language of cardinality $\kappa$. I think it is something weird here. Am I wrong with something?  I had googled it but I have get nothing from websites, now I am confused. Could someone please help? Thanks so much!  EDIT: Latter I am told that in my course, the cardinality of a language refers to the set of expression instead of this of the set of strings. So now I need to consider further about when a string makes sense.  EDIT':Now I am considering that if we can find out a general way to determine the cardinality of expression, which may related to combinatorics. See this question:  Any help would be appreciate. Are there any guidelines for converting cooking recipes from Regular Ovens to Convection? I was looking to buy a Convection Oven and wanted to know if there are any general differences in baking methods between the two. Why can't we initialize members inside a structure? Why can't we initialize members inside a structure ?  example:  struct s {    int i = 10; }; When solving this issue (  ), I did a function so that the plugin would auto-hide from all users except one (me:).  The flaw is that it only auto-hides when active.  At first, it was a mu-plugin, but I had to enable/disable it manually. It really doesn't need to run all the time, as it may slow the site (?) or even contain some sensitive manipulation of the site's language (another question mark).  But mainly the motivation is that I don't want the client activating/deactivating/deleting this plugin (is for my own use), and don't want it cluttering her own plugins list.  So, decided to split the functions in two plugins:   One is a Must-Use used to hide the regular one.  The other will be activated/deactivated upon necessity and is the one from the above linked issue.   But now I run into another question: how to hide one plugin from the Must-Use listing? Ubuntu touch - remote access to device in our company we developed an android app installed on nexus 7 tablets and on tablet we release to several customers. This app stays in foreground active 24/7 but we have problems in monitoring  the devices due to the restrictive access policies of unrooted Android devices.   We can't for example reboot the device remotely.  We are evaluating the possibility of installing Ubuntu touch to replace android on this tablets. Does Ubuntu touch offer more freedom for the remote access of the device? May I do remotely everything I could do normally with the tablet?   Moreover, are the apps developed with ubuntu sdk stable enough to run 24/7?  Thanks I'm pretty sure that you can't take a magnifying glass and make it focus to a point that is hotter than the surface of your light source. For example, when you're outside trying to fry ants with your magnifying glass, it's impossible to get it hotter than 5,000 C (the temperature of the surface of the sun). My dad was arguing with me about it because he didn't see why this was true. My easiest argument was that the 2nd law of thermodynamics prevents this from happening because heat can't flow passively from a place of lower energy/entropy to a place of higher energy/entropy. He didn't buy it, saying that there wasn't anything preventing the light from focusing to a hotter point.  So I was wondering, are there some laws of optics that prevent this from happening? Or alternatively, is there a way to show that you could build a perpetual motion machine from this? Any help is appreciated. Why catch Exceptions in Java, when you can catch Throwables? We recently had a problem with a Java server application where the application was throwing Errors which were not caught because Error is a separate subclass of Throwable and we were only catching Exceptions.  We solved the immediate problem by catching Throwables rather than Exceptions, but this got me thinking as to why you would ever want to catch Exceptions, rather than Throwables, because you would then miss the Errors.  So, why would you want to catch Exceptions, when you can catch Throwables?