sql-server-2008-r2

SQL: find continuous date ranges across multiple rows?

亡梦爱人 提交于 2019-12-10 13:41:18
问题 I'm trying to get a start and end date combination for continuous spans of time worked. The spans can cross multiple rows, where the end date of the first row is the same as the end date of the next row. The intended result is to show a continuous date range with the sum of hours worked for that range. person startdate enddate hours ------ ----------------------- ----------------------- ------ 5163 2013-04-29 07:00:00.000 2013-04-29 11:00:00.000 4.00 5163 2013-04-29 11:30:00.000 2013-04-29 15

Microsoft Office 12.0 Access Database Engine OLE DB Provider missing from SQL Server 2008 R2?

巧了我就是萌 提交于 2019-12-10 13:39:36
问题 I'm trying to import an .accdb MS Access database into SQL Server 2008 R2, but cannot find the Microsoft Office 12.0 Access Database Engine OLE DB Provider in the provider list for both the import wizard, and the SSIS. Tried both and not there. I downloaded and installed MS Access Database Engine 2010, and MS Access Engine 2013, but still not there. How to add this so it will show up in SQL Server 2008 R2? 回答1: Solution : Download 2007 Office System Driver: Data Connectivity Components from

How to pass a Null date variable to SQL Server database

不羁的心 提交于 2019-12-10 12:58:08
问题 I am looking for the best practice, real solution, to send a Null to a SQL Server 2008 R2 database table, when a date is unknown. I read some inputs from a formview, and a date field maybe unknown. The database allows Null values in the field but the VB to store the Null prior to a parameterized query update is not working/eludes me. Dim tb2 As TextBox = TryCast(FormView1.FindControl("tbPurchDate"), TextBox) Dim purDT As Date If tb2.Text = "" Then IsDBNull(purDT) ' Tried this along with other

SQL Server 2008 GET DATETIMEOFFSET according to machine settings

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:45:00
问题 On SQL Server 2008 R2, I have following T-SQL code: SELECT CAST(GETDATE() AS DATETIMEOFFSET); This gives me the result as below: 2011-12-26 10:21:13.7970000 +00:00 But the result is what I wanted to be. It should be this: 2011-12-26 10:21:13.7970000 +02:00 Here is my machine's Date and Time Settings : The same thing happens while I am inserting a value: DECLARE @foo AS TABLE( fooDate DATETIMEOFFSET ); INSERT @foo VALUES(GETDATE()); SELECT * FROM @foo; This gets me the same wrong result (at

How to add and subtract value from previous rows based on condition

萝らか妹 提交于 2019-12-10 12:24:49
问题 I have a table with values Slno Type Amount 1 P 40 2 C 20 3 P 45 4 P 20 5 C 10 I want to get values for RESULT column. Type Amount RESULT P 40 40 C 20 20 P 45 65 P 20 85 C 10 75 If Type is C then value gets subtracted from previous value, else if Type is P then value gets added to previous values. This is what i've tried: ;WITH FINALMIDRESULT AS (SELECT Type, Value1, Row_number() OVER( ORDER BY Slno ASC) rownum FROM #midRes) SELECT C1.Type, C1.Value1, CASE WHEN C1.Type = 'C' THEN (SELECT Sum

Sql for xml: how to avoid a specific field is output as attribute?

筅森魡賤 提交于 2019-12-10 12:18:31
问题 The stating point for this qusetion is Control on XML elements nesting using FOR XML I would like that the output changes from <security AccessLevel="5" /> to <security>5<security/> Basically instead of displaying AccessLevel as attribute I would like its value becomes the value of the element security . How to achieve such a result. I copy here the example from the linked post for clarity: DECLARE @Employees table( EmpID int NOT NULL, Name nvarchar(50), Surname nvarchar(50), DateOfBirth date

SQL Server query - calculate availability of rooms

℡╲_俬逩灬. 提交于 2019-12-10 12:16:44
问题 I have a table name RoomInventory that has data like below Date (Date) RoomsAvailable (int) 1-Jul-2015 30 2-Jul-2015 30 3-Jul-2015 30 5-Jul-2015 28 6-Jul-2015 28 7-Jul-2015 28 8-Jul-2015 30 9-Jul-2015 30 10-Jul-2015 26 11-Jul-2015 28 12-Jul-2015 28 The result which I want is like below: StartDate EndDate RoomsAvailable ---------------------------------------------- 1-Jul-2015 3-Jul-2015 30 5-Jul-2015 7-Jul-2015 28 8-Jul-2015 9-Jul-2015 30 10-Jul-2015 10-Jul-2015 26 11-Jul-2015 12-Jul-2015 28

SQL Server - simple way to create pivot

删除回忆录丶 提交于 2019-12-10 12:06:36
问题 Does anybody knows a simple way to create a pivot of this result: [0-1] [1-2] [2-3] [3-4] 12 45 29 5 This result is created with query: SELECT [0-1] = SUM(CASE WHEN AGE >= 0 AND AGE <= 1 THEN 1 ELSE 0 END), [1-2] = SUM(CASE WHEN AGE > 1 AND AGE <= 2 THEN 1 ELSE 0 END), [2-3] = SUM(CASE WHEN AGE > 2 AND AGE <= 3 THEN 1 ELSE 0 END) FROM dbo.Persons I want to show the column values as rows i.e the output should like this: [0-1] 12 [1-2] 45 [2-3] 29 [3-4] 5 Links to articles/blogs are also

SQL Server — Improve Speed of Cursor

喜夏-厌秋 提交于 2019-12-10 11:56:31
问题 I am using the below code to check if column @act_value is above 24.0 for a specific row, looping through each row of the table with a cursor. If @act_value is above 24.0, then several operations will be completed as well as updating that entry and inserting a new entry. That said, the query takes over 26 min to run (up from 0:16 min prior to this addition provided below) and perhaps too resource intensive. Is there a better configuration that can speed up this operation? DECLARE cur_hours

Is it possible to create User-Defined Data Types when using EF 4.1 Code First?

谁说胖子不能爱 提交于 2019-12-10 11:41:32
问题 When using EF 4.1 Code First, is it possible to create User-Defined Data Types for your schema? 回答1: Simple answer is no. Longer answer: Current EF implementation leads to multiple issues when trying to use user defined types: The type must be defined prior to its usage in table's DDL definition. Because of that the type cannot be defined in Seed method of database initializer (as often used for other database constructs like triggers or indexes). To make this work you must create whole new