sql-server-2005

Sql Server: Count records (including zero) per ten-minute intervals

十年热恋 提交于 2019-12-12 09:22:53
问题 I currently have a table (SQL Server 2005) that logs the visits against my web app, and I want to put together some code to report (and display a visualization) of that traffic. What I want is to display the number of visits during each ten-minute interval over the last 24 hours. I have a query that does just that, but there are ten-minute intervals during which there are no visits, and I would like to adjust my query to display a zero count for those intervals. I imagine I could come up with

SQL Permissions to Add data and how to verify?

旧巷老猫 提交于 2019-12-12 09:15:10
问题 I'm looking for a good way to maintain permissions on who can add data to a database in a C# app and SQL Server 2005. I need to explain though to make this clear. So let's take an example of this: I have two users Bob and Jim , both have been added to the SQL permissions so they have write access to the database. Now all access is based on Domain User Accounts. All other users only have read access. Now I have a couple tables such as: Users UserPermissions Books BookPublishers So

Insert a Row Only if a Row does not Exist

南楼画角 提交于 2019-12-12 09:06:10
问题 I am building a hit counter. I have an article directory and tracking unique visitors. When a visitor comes i insert the article id and their IP address in the database. First I check to see if the ip exists for the article id, if the ip does not exist I make the insert. This is two queries -- is there a way to make this one query Also, I am not using stored procedures I am using regular inline sql 回答1: Here are some options: INSERT IGNORE INTO `yourTable` SET `yourField` = 'yourValue',

Is there any way/tool to identify estimate query run time in SQL sERVER

筅森魡賤 提交于 2019-12-12 09:05:22
问题 I have been google about this for a while..is there any way to identify the estimated query execution time> There are actual execution plan and estimated execution plan on the ssms .The thing is none of these have estimated time. Is it something lacking in the Sql Server? 回答1: Currently, no. Microsoft is currently researching ways to do this using a combination of work already completed and an estimated execution plan (See the details of their research on the Microsoft Research site), so we

Delete All / Bulk Insert

十年热恋 提交于 2019-12-12 08:48:18
问题 First off let me say I am running on SQL Server 2005 so I don't have access to MERGE . I have a table with ~150k rows that I am updating daily from a text file. As rows fall out of the text file I need to delete them from the database and if they change or are new I need to update/insert accordingly. After some testing I've found that performance wise it is exponentially faster to do a full delete and then bulk insert from the text file rather than read through the file line by line doing an

cursor to update a row with values from the previous and current rows

北战南征 提交于 2019-12-12 08:48:12
问题 Fellow Query Writers, I have a table as follows: myTable t1 col2 col3 2 1 3 0 4 0 5 0 6 0 and I want to update each zero on col3 with the value of col3 in the previous row plus the value of col2 in the current row. So my table would de like the following: myTable t1 col2 col3 2 1 3 4 (1+3) 4 8 (4+4) 5 13 (5+8) 6 19 (6+13) I'm missing the logic here, short-sightedness perhaps. I was trying it with a cursor as follows: DECLARE @var3 FLOAT DECLARE cursor3 CURSOR FOR SELECT col2, col3 FROM table1

Why does 'HASH JOIN' or 'LOOP JOIN' improve this stored proc?

爱⌒轻易说出口 提交于 2019-12-12 08:46:50
问题 I have a basic query that goes from 6 seconds to 1 second just by changing one join from LEFT JOIN to LEFT HASH JOIN or 'LEFT LOOP JOIN'. Can anyone explain why this would cause such a large increase in performance and why SQL's optimizer isn't figuring it out on it's own? Here is roughly what the SQL looks like: SELECT a.[ID] FROM [TableA] a LEFT HASH JOIN [TableB] b ON b.[ID] = a.[TableB_ID] JOIN [TableC] c ON c.[ID] = a.[TableC_ID] WHERE a.[SomeDate] IS NULL AND a.[SomeStatus] IN ('X', 'Y'

SQL Server 2005 - How often should you rebuild Indexes?

天大地大妈咪最大 提交于 2019-12-12 08:39:44
问题 I recently took over a project and they have a SQL job setup to run every three hours which rebuilds the indexes found within the ASP.NET Membership database tables. This seems pretty high, to rebuild indexes 8 times a day. I get about 2000 new users every day, and a total of about 2 million registered users. What would you recommend for a proper index rebuilding schedule? 回答1: Your deadlocks can definitely be related to the rebuilding of the indexes. There is also no doubt that those indexes

How to design Query for creating dynamic columns from rows

只谈情不闲聊 提交于 2019-12-12 08:35:02
问题 I have data Table1 ID Name ----------- 1 n1 2 n2 3 n4 Table2 FID YearS Val ---------------------- 1 2008 Up 1 2009 Down 1 2010 Up 2 2000 Up 2 2001 Down 2 2002 Up 2 2003 Up 3 2009 Down 3 2010 Up I want to return data in following format: ID Yr1 Val1 Yr2 Val2 Yr3 Val3 Yr4 Val4 -------------------------------------------------------- 1 2008 Up 2009 Down 2010 Up NULL Null 2 2000 Up 2001 Down 2002 Up 2003 Up 3 2009 Down 2010 Up NULL NULL NULL Null Based on maximum no of columns for ID i want to

How to collate SQL_Latin1_General_CP1_CI_AS using IN operator

不想你离开。 提交于 2019-12-12 08:29:36
问题 I want to filter records on 'Email' my query is like this. SELECT * FROM #temp WHERE email NOT IN (SELECT email FROM Customer) It gives me following error Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation. I can use collate if there is equal operator (=) instead of IN. But using Collate here gives me syntax error. SELECT * FROM #temp WHERE email NOT IN (SELECT email FROM Customer) collate SQL_Latin1_General_CP1_CI