sql-server-2005

SQL how to sum events in one hour between two dates and show it in one row

瘦欲@ 提交于 2019-12-21 17:52:37
问题 I am developing a report with C# and SQL server 2005, I have to only show how many hit we got in each hour. the table is very huge. output should look like this: Row# | Date | Time | Hit Count ----------------------------- 1 | 07/05/2012 | 8:00 | 3 2 | 07/05/2012 | 9:00 | 4 3 | 07/05/2012 | 10:00 | 0 4 | 07/05/2012 | 11:00 | 5 My table is look like this: "HitTime": 07/05/2012 08:02:24 07/05/2012 08:12:21 07/05/2012 08:23:00 07/05/2012 09:01:00 07/05/2012 09:08:14 07/05/2012 09:12:31 07/05

Hibernate Query runs slow in the system, but fast when run directly

眉间皱痕 提交于 2019-12-21 17:46:21
问题 I have a problem similar to the on in this weeks podcast. We have a Java application using hibernate with Sql Server 2005. Hibernate is generating a Query for us that is taking nearly 20 minutes to complete. If we take the same query using show_sql and replace the questions marks with constant value the answer is returned immediately. I think we need option(recompile), but I can't figure out how to do that with HQL. Please help! 回答1: From the description of your problem, it sounds like you're

T-SQL: what COLUMNS have changed after an update?

微笑、不失礼 提交于 2019-12-21 17:06:04
问题 OK. I'm doing an update on a single row in a table. All fields will be overwritten with new data except for the primary key. However, not all values will change b/c of the update. For example, if my table is as follows: TABLE (id int ident, foo varchar(50), bar varchar(50)) The initial value is: id foo bar ----------------- 1 hi there I then execute UPDATE tbl SET foo = 'hi', bar = 'something else' WHERE id = 1 What I want to know is what column has had its value changed and what was its

Re-indexing large table - how screwed am I?

我只是一个虾纸丫 提交于 2019-12-21 15:00:04
问题 I have a 1 TB, 600m row, table which has a misguided choice of indexed columns, specifically a clustered index on the primary key column which is never used in a select query. I want to remove the clustered index from this row and create it on a number of other rows. Table is currently like this: colA (PK, nvarchar(3)) [clustered index pt b] colB (PK, bigint) [clustered index pt a] colC (DateTime) [non-clustered index] colD (Money) [non-clustered index] colE (bit) [no index] colF (bit) [no

Deploying Sql Server Reporting Services reports on production boxes

喜夏-厌秋 提交于 2019-12-21 11:54:49
问题 How to deploy Sql server reports on productions boxes? Locally it's not a problem, I just specify the url and then right click on project and say deploy which deploy on my local server. But it's not gonna be the case for the production server 回答1: I recommend you create rs scripts that can be executed on production server. Take a look at Reporting Services Scripter. It's creates deployment scripts based on your current installation. http://www.sqldbatips.com/showarticle.asp?ID=62 回答2: Either:

How to Use Group By clause when we use Aggregate function in the Joins?

[亡魂溺海] 提交于 2019-12-21 10:49:55
问题 I want to join three tables and to calculate the Sum(Quantity) of the Table A. I tried something and I get the desired output. But still I have confusion based on aggregate function and Group By clause. While calculating the sum value by joining two or more tables, what are the columns we need to mention in the Group By clause and why do we need to give those columns? For Example: Here is my table and the desired query. TableA: ItemID, JobOrderID, CustomerID, DivisionID, Quantity TableB:

SQL Server 2005 Error 701 - out of memory

半城伤御伤魂 提交于 2019-12-21 09:42:28
问题 I'm currently having following error message when executing a .sql file with about 26MB on SQL Server 2005: Msg 701, Level 17, State 123 There is insufficient system memory to run this query. I'm working with 4GB RAM, 64Bit Windows 7 Ultimate, Core2Duo T6400(2GHz)... Is there a way to execute it without receiving this message (maybe force SQL Server to use swap file?) or a way to execute it in parts (like 100 queries a time)... The file is basically a CREATE TABLE followed by thousads of

How do you add a NOT NULL FOREIGN KEY column to an existing (populated) table in MS SQL?

强颜欢笑 提交于 2019-12-21 09:36:37
问题 I need to add a NOT NULL column to an existing (populated) table that will be a foreign key to another table. This brings about two problems: When you add the column, its value cannot be null - using a default is not an option (unless it is removed later on) because the database logic is used in the server side validation when a user enters a new record i.e. when the application tries to add a record with this field having a null value, the database throws an error that the application

SQL Server application role, performance hit

淺唱寂寞╮ 提交于 2019-12-21 09:26:26
问题 I plan to use MS SQL Server 2005 application roles in my application. I will start the role by executing the sp_setapprole and finish by executing the sp_unsetapprole SPs. The application is implemented in ASP.NET. I've read that "connection pooling doesn't work" with application pooling and there is no way to react on connection "disconnect event" (execute sp_unsetapprole just before disconnection). I plan to call sp_setapprole at the start of all my SPs and call sp_unsetapprole at the end

How to convert datetime to date only (with time set to 00:00:00.000)

做~自己de王妃 提交于 2019-12-21 08:24:10
问题 I have a string '2009-06-24 09:52:43.000', which I need to insert to a DateTime column of a table. But I don't care about the time, just want to insert it as 2009-06-24 00:00:00.000 How can I do that in T-SQL? 回答1: For SQL Server 2005 and below: CONVERT(varchar(8), @ParamDate, 112) -- Supported way CAST(FLOOR(CAST(@ParamDate AS float)) AS DATETIME) -- Unsupported way For SQL Server 2008 and above: CAST(@ParamDate AS DATE) 回答2: declare @originalDate datetime select @originalDate = '2009-06-24