sql-server

Calculate Time Difference Between Two Rows SQL Server

I have a table that contains the following: DataDate Value 2010-03-01 08:31:32.000 100 2010-03-01 08:31:40.000 110 2010-03-01 08:31:42.000 95 2010-03-01 08:31:45.000 101 . . . . . . I need to multiply the value column by the difference in time bet...

Tamperproof table

I'm designing a table that will be used to store information on which customers will be charged. The problem is the database could be on the customers servers. I was thinking of adding a second table containing a hash of the first, so that the software using the database can update the database and the hash, but the customers can't edit ...

Find the Friday that a particular date is "closest" to in T-Sql

I'm looking for an elegant simple way to determine the date of the Friday that is closest to a particular date. Any ideas? ...

valid record in SQL query

I have a table with few columns and one of the column is DockNumber. I have to display the docknumbers if they confirm to a particular format First five characters are numbers followed by a - and followed by 5 characters. The last but one character should be a alpha. 12345-678V9 How can I check in SQL if the first 5 characters are nu...

Best equivalent for IsInteger in SQL Server

What is the best way to determine whether or not a field's value is an integer in SQL Server (2000/2005/2008)? IsNumeric returns true for a variety of formats that would not likely convert to an integer. Examples include '15,000' and '15.1'. You can use a like statement but that only appears to work well for fields that have a pre-det...

Syntax for Alter Column and Add Column in same query

Is it possible to both alter a column and add a new column in the same alter table query for MSQL? I've tried looking at the below MSDN article, but it was a bit confusing to understand. I could easily do it with multiple queries, but would rather do it with one query if possible. Thanks. http://msdn.microsoft.com/en-us/library/ms19027...

how to force installation of management studio?

i already had 2008 express sql server but for some reason it came without management studio. how do i know? because i went programs->sql server 2008 and there was no GUI there. so i went here to download the entire thing again, supposedly WITH management studio: http://www.microsoft.com/downloads/details.aspx?FamilyID=7522a683-4cb2-454...

PerformancePoint dashboard permissions problem in MOSS

I have a PerformancePoint dashboard running in MOSS 2007 portal. The dashboard consists of one SSRS 2005 report, running in SharePoint Integrated mode. NT Authority\Authenticated Users have read permissions to the report library containing the SSRS report, the dashboard, and the report library containing the dashboard. Users that atte...

SQL-92 Query to find earliest date dependent on column value changing

I am querying a data system with an OLEDB interface that supports SQL92. My query problem is equivalent to the one solved here: http://stackoverflow.com/questions/2034094/sql-query-to-find-earliest-date-dependent-on-column-value-changing, but the solution provided there and copied below is too advanced for SQL92: SELECT JobCodeId, M...

Count number of 'overlapping' rows in SQL Server

Hi all, I've been asked to look at a database that records user login and logout activity - there's a column for login time and then another column to record logout, both in OLE format. I need to pull together some information about user concurrency - i.e. how many users were logged in at the same time each day. Do anyone know how to...

Get "next" row from SQL Server database and flag it in single transaction

I have a SQL Server table that I'm using as a queue, and it's being processed by a multi-threaded (and soon to be multi-server) application. I'd like a way for a process to claim the next row from the queue, flagging it as "in-process", without the possibility that multiple threads (or multiple servers) will claim the same row at the sam...

sql server 2008 database merging with another database

I have 2 sql server databases on two different remote servers. On day one, they were both exaclty the same. But over time, there are changes in both (different, tables, stored procs, views, etc..). How do I merge them together, so I have one again - the same Database in both places? ...

How to get SQL Server XQUERY to return something other than "There is no element named [Element]"

Apologies if this is answered elsewhere. I keep getting the error message XQuery [Mytable.XMLData.nodes()]: There is no element named 'Answer' SELECT ref.value('/','nvarchar(1000)') FROM Mytable CROSS APPLY xmldata.nodes('Answer') R(ref) - --XML of Row <Answer xmlns="http://TempNameSpace.com/AnswerData.xsd" Type="Deliverable"> <...

Question about SQL Server Optmization Sub Query vs. Join

Which of these queries is more efficient, and would a modern DBMS (like SQL Server) make the changes under the hood to make them equal? SELECT DISTINCT S# FROM shipments WHERE P# IN (SELECT P# FROM parts WHERE color = ‘Red’) vs. SELECT DISTINCT S# FROM shipments, parts WHERE shipments.P# = p...

Anonymous Report Viewing with SQL Server Reporting Services 2008?

In SQL Server 2005, setting up an anonymous user to view a report was simple (just create a windows user with limited privileges and give that user permission to see the report in IIS). However, in 2008, it seems more complicated. Under my present configuration, users require domain authentication to view reports. There does not seem t...

Connecting ASP.NET to MDF file

I finally got SQL Server Management Studio to work. I attached the Adventure Works sample database to it. Now I would like to display data from that database in ASP.NET. I would like to run SQL statements from ASP.NET. How do I do this? ...

add a connection to database not working, asp.net to mdf

i am adding a connection in asp.net using visual web developer to sql server database file, it's an MDF file. when i click test connection i get this: can someone please help me set up this connection ...

Notifier for System Tray - Fire when new record gets created in SQL Server

Work on a support helpdesk. New tickets come in and records are created in a SQL Table and they are dumped to a specific category where any analyst can pick them up. Front end does not notify analysts when there are new tickets, so have to contonously refresh the front-end (browser) to see if new tickets are coming into the 'To Be Assign...

Best practice for archiving a huge table of over 1,000,000,000 rows

I'm using SQL Server 2005. There is an audit trail table, containing over 1,000,000,000 rows. I'm planning to archive this table. When I make a simple select with nolock, I can still find blocking (probably IO blocking with other process?). So are there any best practice for this kind of situation? ...

not connecting because read-only (sql server, mdf file)

this is a different question concerning: http://stackoverflow.com/questions/2360433/add-a-connection-to-database-not-working-asp-net-to-mdf i am unable to connect because of the noted error message the database must be read only? but when i click the properties of the file read only is not checked is there another way it could be rea...