sql-server

How to find fifth highest salary in a single query in MS Sql Server

How to find fifth highest salary in a single query in MS Sql Server ...

Upgrading from SQL Server 2005 to 2008

I have upgraded from SQL Server 2008 to SQL Server 2005 using the upgrade wizard. Once completed I found that SQL 2005 still exists. I used the same instance that was in SQL Server 2005, but I can’t connect. And all data, which are stored on SQL Server 2005, are not found on SQL Server 2008 with the same instance. Do I need to import the...

How to Search date in SQL?

Hi, I am having an Event Management System in which i want, If an event is registered for 5 days (21 jan 2009 to 26 Jan 2009) Then if another person wants to register an event between 22 jan 2009 to 24 jan 2009 then it will not allow to register. I want to check this using SQL query, so please tell me how can i do this. ...

Unaccounted for database size

I currently have a database that is 20GB in size. I've run a few scripts which show on each tables size (and other incredibly useful information such as index stuff) and the biggest table is 1.1 million records which takes up 150MB of data. We have less than 50 tables most of which take up less than 1MB of data. After looking at the siz...

Mapping existing tables to Domain classes in C#

Hi, I don't even know if I'm using the correct terms but here goes: Is there a way to map the tables and their relations in a SQL Server to domain (C# code) automatically, by means of a tool or something? I've used the nhibernate plugin, but it creates a file in .cs and another in xml, that has the mapping, but I want that mapping to b...

Why is the default length for VARCHAR 30 when using CAST?

In SQL server 2005 this query select len(cast('the quick brown fox jumped over the lazy dog' as varchar)) returns 30 as length while the supplied string has more characters. This seems to be the default. Why 30, and not 32 or any other power of 2? ...

How to assess performance of MDX in OLAP processing

I am familiar with standard practices to assess performance query or stored procedure using SQL server 2000/2005/2008. How is the best way to assess MDX performance? I assume its possible to write structurely correct but poor performance MDX queries as easily as you can with standard T-SQL? Any suggestions? FYI: I may be tasked with o...

Best way to update table schema for huge tables (SQL Server)

I have a few huge tables on a production SQL 2005 DB that need a schema update. This is mostly an addition of columns with default values, and some column type change that require some simple transformation. The whole thing can be done with a simple "SELECT INTO" where the target is a table with the new schema. Our tests so far show tha...

Web front-end for SQL Server Database Mail

SQL Server 2005 introduced Database Mail for sending e-mail messages from the SQL Server Database Engine in a robust fashion. Database Mail comes with a number of interesting views like sysmail_allitems, sysmail_sentitems, sysmail_faileditems, sysmail_unsentitems, sysmail_mailattachments and sysmail_event_log. Is there any known stand-al...

SQL Server tempdb optimization tips for a new server?

I am planning a fresh installation of SQL Server 2005 on a new machine, which I have to order. I know that tempdb tuning is very important to the overall performance of the SQL Server instance. I've read that it's best practice to create as many tempdb files as you have CPU's (or cores?). Is that correct? Are there any other recommendat...

SQLServer2005: Save complete results of query in a file for some long text data types

Lets say a have a table t (id int, someVeryLongText text) and want to store the result of a query: select someVeryLongText from t where id = 1 in the file. In Managemant Studio when I select Tools->Options->QueryResults and choose Results to File It seems that only the first 8192 characters are written to the file. Is there an op...

SQL Server 2005 Change Auditing

Is there a built in way in SQL Server 2005 to audit things specifically like deleting a stored procedure? Is there a history table that I can query? We have a mystery sproc that has disappeared a few times now. ...

SQL Server 2005 -Seeing SPs executing inside SPs

I am wondering if it is possible to see stored procs that are being executed by other stored procs in Sql Server Profiler, is it possible, and if so how? ...

SQL Server UNDO

I am a part time developer (full time student) and the company I am working for uses SQL Server 2005. The thing I find strange about SQL Server that if you do a script that involves inserting, updating etc there isn't any real way to undo it except for a rollback or using transactions. You might say what's wrong with those 2 options? We...

SQL Server to Excel 2007 - New Lines

I'm trying to retrieve data from an SQL Server 2000 server, and place into Excel. Which sounds simple I know. I'm currently Copying, and Pasting into Excel, from Management Studio The problem is one of the columns is an address, and it’s not retaining the newlines. These new lines have to stay in the same cell in excel, I.E cannot take ...

SQL Server Indexes Aren't Helping

I have a table (SQL 2000) with over 10,000,000 records. Records get added at a rate of approximately 80,000-100,000 per week. Once a week a few reports get generated from the data. The reports are typically fairly slow to run because there are few indexes (presumably to speed up the INSERTs). One new report could really benefit from ...

When connecting SAP Business One to SQL Server 2005, what is the

we have SAP Business One - Fourth Shift Edition running here at a small manufacturing company. The consulting company that has come in to do the installation/implementation uses the "sa" id/pass to initially connect to the database to get the list of companies. From then on, I have to assume that its the sa id/pass that is being used t...

SQL Query Advice - Most recent item

I have a table where I store customer sales (on periodicals, like newspaper) data. The product is stored by issue. Example custid prodid issue qty datesold 1 123 2 12 01052008 2 234 1 5 01022008 1 123 1 5 01012008 2 444 2 3 02052008 How can...

Good database client (MS SQL Server) with auto-complete, small memory foot-print and free?

Hi, Any sugestions? Currently I'm using Squirell but it consumes quiet a bit of memory... I just use the sql client to run some queries and get the result but i absolutely need auto-complete of tables, columns, etc ...

T-SQL Background Processing

I'm having the trouble finding the wording, but is it possible to provide a SQL query to a MS SQL server and retrieve the results asynchronously? I'd like to submit the query from a web request, but I'd like the web process to terminate while the SQL server continues processing the query and dumps the results into a temp table that I ca...