sql-server

Blank screen when looking at Activity Monitor details

I'm looking at the Activity Monitor in SQL Server 2005 and when I double click a specific process to view the SQL I am given a blank screen. What does this mean? What could be causing this? ...

Activity Monitor Problems in SQL Server 2005

I am looking at the Activty Monitor for SQL Server 2005 and we have some processes that are taking up large amounts of the CPU. When I look at what is trying to be run I get: set transaction isolation level read committed This code is not coming from any of our applications. What is causing it? What should be done? ...

Design query for following scenario

I have two tables - Table1: id name number ------------------ 1 x1 123 2 x2 234 ...and Table2: tbl1id title rank -------------------- 1 t1 3 1 t2 2 2 t1 3 1 t3 1 Is there a way I can join them to return result as showing max title based on min rank for given user: id name ...

datetime in where clause

how can i select 12/20/2008 in where clause of sql. it is sql server 2005. select * from tblErrorLog where errorDate = '12/20/2008' ...

How do I add a column to a table in SQL Server that doesn't allow nulls?

I have a table that I want to add a bit column, which I wish to default to false for all existing data. How do I alter my table in such a way that it allows me to specify NOT NULL before I have inserted false for my existing rows? Should I create it as nullable, do an insert than switch it non-nullable? ...

[C#] Compress SQL Server 2005 query results?

Is it possible to reduce network load by compressing sql query results in a transparent way for the client? DB engine : SQL Server 2005 ...

Maintaining a metadata table in SQL

Can someone help giving me some direction to tackle a scenario like this. A User table which contains all the user information, UserID is the primary key on User Table. I have another table called for example Comments, which holds all the comments created by any user. Comments table contains UserID as the foreign key. Now i have to rank...

Getting the minimum of two values in sql

I have two variables, on is called PaidThisMonth, and the other is called OwedPast. They are both results of some subqueries in SQL. How can I select the smaller of the two and return it as a value titled PaidForPast? The MIN function works on columns, not variables. ...

Sql query optimization

I have a query that I want to execute that fastest possible. Here it is: select d.InvoiceDetailId,a.Fee,a.FeeTax from InvoiceDetail d LEFT JOIN InvoiceDetail a on a.AdjustDetailId = d.InvoiceDetailId I put an ascending index on AdjustDetailId column I then ran the query with 'Show Actual Execution Plan' and the result estimated subt...

Help me refactor this monster of a query

This is one huge monster, it's going into a SP so variables are usable: SELECT OwnerName, SUM(AmountPaid) AS Paid, SUM(AmountOwedComplete) AS Owed, SUM(AmountOwedThisMonth) AS OwedMonth, SUM(PaidForPast) AS PaidPast, SUM(PaidForPresent) AS PaidPresent, SUM((AmountPaid - PaidForPast - PaidForPresent)) AS PaidFuture, [Description] FROM (...

Sql Server 2008 FTS strange search

Hi guys I have a problem with a FTS on SQL Server 2008. First I am not an expert in that field. The problem is as following. I have a row with column value 'This is it aka Michael Jacksons's This is it'. When user enters in a search box term "This is it" following query returns 0 results. SELECT column_list FROM tabla_name...

What format should I use for scanned invoices in SQL Server?

Hello! My client currently scans invoices and similar documents into PDF format, and stores them in the file system. I suggested to him that we store the scans in their custom management system's SQL Server to remove one of the 'moving parts' of their system. My original idea was to store them in a lossless graphics format, but the ac...

Is there a better way to read one xml value from the database

I'm currently using this code fragment to retrieve the one xml value that will be returned from my scalar query. using (SqlDataReader reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { SqlXml xml = reader.GetSqlXml(0); XmlSchema xmlSchema = XmlSchema.Read(xml.CreateReader(), validationEvent); ...

What is an easy way to deploy database changes using SQL Server?

The software system I work on is a medical billing system, large amounts of data and data tables, and stored procedures. I was reading the article "12 Steps to Better Code" and in The Joel Test #2 states: Can you make a build in one step? Now I was wondering, does this mean deployment build (so that a customer can update their deployme...

Suggestions for improving count performance on a SQL query?

I've got a query that is taking a very long time to run due to a select similar to: SELECT Count( Distinct t1.v1), Count (Distinct Case t2.v1 When 'blah' then t1.v1 Else null End ), .... FROM t1 LEFT JOIN t2 ON t1.v3 = t2.v3 WHERE t1.myDate BETWEEN @start and @end AND t2.v5 = @id Can anyone suggest any good methods for improving thi...

SQL - using a variable for an IN clause

I wish to do something like the following: declare @FrameNumber nvarchar(20) set @FrameNumber = '(p1, p2)' select from myTable where c1 in @FrameNumber What is the correct syntax for this? (for note: I need to pass the value of @FrameNumber in as a parameter to the stored procedure... so I have to at least use the string "p1, p2") ...

Error on inserting data in SQL Server db from Excel Sheet

I am inserting data from an Excel sheet to SQL Server 2005 db. I am getting this error randomly, sometimes after 20-30 records and sometimes after 1000s. I am unable to find the reason. I am using Visual Studio 2008. The CLR has been unable to transition from COM context 0x21a7b0 to COM context 0x21a920 for 60 seconds. The t...

Site update, testing was fine, after deployment, again fine, once user load increases, FAIL?

We are using ASP.NET MVC with LINQ to SQL. We added some features and tested them all to perfection on our QA box. We are using Windows Server 2003 and SQL Server 2005. So when we pushed out changes to the Live web server we also used Red Gate SQL Compare to push new database changes to the LIVE database. We tested again between the few ...

Which is the most common ID type in SQL Server databases, and which is better?

Is it better to use a Guid (UniqueIdentifier) as your Primary/Surrogate Key column, or a serialized "identity" integer column; and why is it better? ...

Query to retrieve Text data type column value based on MAX value in other column

Hi I have a table with following columns and data FldID | Rev | Words 10257       2        Some text is present here 10257        3        I changed this text 10258        2        Some more text for another item 10258        3   ...