sql-server-2012

Concatenating a single column into a single row in SQL Server Management Studio

北慕城南 提交于 2019-12-23 02:52:57
问题 I am trying to compile a list of dumpsters at a given location that a driver needs to pick up. I have a table like this: Stop Number Dumpster Number ------------------------------------ 1 245 1 248 2 312 2 314 2 316 I would like it to look like this: Stop Number Dumpster Number ------------------------------- 1 245 248 2 312 314 316 The code I built is below, but I am getting the same result as the first table, with just the spaces on the end. SELECT [StopNumber], CAST((CONCAT([ContainerID],'

Use sql server Convert Function to convert hijri to gregorian date

烈酒焚心 提交于 2019-12-23 02:43:10
问题 I have simple table on my sql server and in my table have a date field,and into date field save a hijri date ,i want use the sql server convert function to convert hijri date to gregorian date . how can i do this? i use this query in sql server: update k set time=CONVERT(datetime,GETDATE(),101) and i insert this "1392/4/21" in time field ,and when convert sql server return this "2014/11/5" ,when i use online date convertor,and insert this "2014/11/5" ,convert date is "1393/2/14" !!is this the

Making sense of 'OFFSET/FETCH' in SSMS 2012

点点圈 提交于 2019-12-23 02:05:13
问题 Just installed Microsoft SQL Server Management Studio 2012 today. In familiarizing myself with the pagination feature addition of ORDER BY, I keep running into this error: Msg 102, Level 15, State 1, Line 5 Incorrect syntax near 'OFFSET'. Msg 153, Level 15, State 2, Line 6 Invalid usage of the option NEXT in the FETCH statement. Here is my query: SELECT SingleWomansName, NumberOfCats FROM CatLadies WHERE NumberOfCats > 1 ORDER BY NumberOfCats OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY I've seen

SQL to check when pairs don't match

回眸只為那壹抹淺笑 提交于 2019-12-23 01:47:05
问题 I am using SQL Server 2012 I have the following sample data Date Type Symbol Price 6/30/1995 gaus 313586U72 109.25 6/30/1995 gbus 313586U72 108.94 6/30/1995 csus NES 34.5 6/30/1995 lcus NES 34.5 6/30/1995 lcus NYN 40.25 6/30/1995 uaus NYN 40.25 6/30/1995 agus SRR 10.25 6/30/1995 lcus SRR 0.45 7/1/1995 gaus 313586U72 109.25 7/1/1995 gbus 313586U72 108.94 I want to filter out when symbol and price match. It's ok if type doesn't match. Thus with the above data I would expect to only see Date

How to get convert server time to local time and deal with daylight saving time

送分小仙女□ 提交于 2019-12-23 01:10:08
问题 I host my website (asp.net webforms, .Net 4.5, SQL Server 2012) on Godaddy and they (the server) use Mountain Standard Time ( -7 compare to UTC time) which is never changed and does not observe daylight saving time. So if I do Response.Write("UTC Time: " + DateTime.UtcNow.ToString() + "<br/>"); Response.Write("Server Time: " + DateTime.Now.ToString() + "<br/>"); Response.Write("Server DateTimeOffset: " + DateTimeOffset.Now.ToString() + "<br/>"); It will display this: UTC Time: 9/18/2015 5:14

Logging update operation in triggers

拥有回忆 提交于 2019-12-22 18:17:21
问题 I have an UPDATE trigger that produces INSERTED and DELETED table like this: INSERTED Id Name Surname 1 Stack Overflow 2 Luigi Saggese DELETED Id Name Surname 1 Stacks Overflow 2 Luigi Sag I want to capture this update to a log table. My Log table (that is global for all tables) is like this (then I must process my INSERTED and DELETED table): Id_Table Table_Key_Value Id_Value Old_Value New_Value 12345 1 4556645 Stack Stacks 12345 1 544589 Overflow Overflows 12345 2 544589 Saggese Sag Id

SQL Cross Tab Query

青春壹個敷衍的年華 提交于 2019-12-22 18:15:10
问题 Need help figuring out how to do a cross-tabulated report within one query. There are 3-4 tables involved but the users table may not need to be included in the query since we just need a count. I have put together a screenshot of the table schema and data as an example which can be seen below: What I need it to return is a query result that looks like: So I can make a report that looks like: I've tried to do cursor loops as it's the only way I can do it with my basic knowledge, but it's way

Use of temporary functions or procedure within a script

橙三吉。 提交于 2019-12-22 15:24:29
问题 I am using SQL Server 2012 , i have a script by which i am inserting values to a table, in that script i have to convert the format of some DateTime variables on the basis of two parameters. I can do it using CASE or if condition in sql . I am not allowed to make any Function or procedure in the database to which i can refer. Is there any other way like creating a temporary function or temporary procedure within the script to apply condition alter the format for Datetime values? 回答1: Yes you

How perform lockmode:none on associations (join) with Doctrine2 and SQL Server

隐身守侯 提交于 2019-12-22 12:38:14
问题 I'm trying to append the With(nolock) hint to my Queries using Doctrine2. I tried using the ->setLockMode(LockMode::NONE)->getSQL(); but it didn't work as expected, it added the WITH(NOLOCK) just to the ( first ) table in the FROM clause. I'll explain: $dql='SELECT e, o FROM Porject:Example e JOIN e.owner o'; $query = $this->getEntityManager()->createQuery($dql); try{ $this->getEntityManager()->getConnection()->beginTransaction(); $result = $query ->setLockMode(LockMode::NONE)->getSQL();

Calculate sum of values in tree(recursive query)

时间秒杀一切 提交于 2019-12-22 12:25:33
问题 I have tree structure in table employees (id,name,parentid) and this table can be nested.employees is one-to-many relation to another table Sales with columns(id, employeeid, quantity). Each employee has Sales Quantity. I want to calculate sum of quantity for each employee along side with child employees. I wrote some code to be more clearly. DECLARE @Employees TABLE(ID INT, Name NVARCHAR(100), ParentID INT); DECLARE @Sales TABLE(ID INT, EmployeeID INT, Quantity INT); INSERT INTO @Employees