sql-server-2005

Debugging SQL Server Slowness: Same Database, Different Servers

For a while now we've been having anecdotal slowness on our newly-minted (VMWare-based) SQL Server 2005 database servers. Recently the problem has come to a head and I've started looking for the root cause of the issue. Here's the weird part: on the stored procedure that I'm using as a performance test case, I get a 30x difference in t...

Computed column should result to string

Here is a snap of my database. Both col1 and col2 are declared as int. My ComputedColumn currently adds the Columns 1 and 2, as follows... col1 col2 ComputedColumn 1 2 3 4 1 5 Instead of this, my ComputedColumn should join the columns 1 and 2 (includimg the '-' character in the middle) as follows... col1 col2 C...

SQL Server copying table information between databases

Hi, I have a script that I am using to copy data from a table in one database to a table in another database on the same SQL Server instance. The script works great when I am connected to the SQL Server instance as myself as I have dbo access to both databases. The problem is that this won't be the case on the client's SQL Server. They...

Can you call a SQL Stored Procedure that returns a record set and have those values loaded into variables?

Hello fellow stackers Please consider the following SQL Server table and stored procedure. create table customers(cusnum int, cusname varchar(50)) insert into customers(cusnum, cusname) values(1, 'Ken') insert into customers(cusnum, cusname) values (2, 'Violet') --The Wife create procedure getcus @cusnum int as Begin select c...

SQL Temp Tables & Replication

I have had an issue with our replication process and would like to salvage some data. I have a process in place where I will connect to each subscriber before flagging them for reinitialization and I will run the below to pull any data they may have entered in during the "dark time". I am pretty sure this will work in a vanilla palace...

How can I programmatically drop a SQL Server database from .NET code

I'm trying to drop a SQL Server database from .NET code. I've tried using the SMO classes but get an exception saying the database is in use. Then I tried executing a query (opening a SqlConnection, executing a SqlCommand), along the lines of: ALTER DATABASE foo SET SINGLE_USER WITH ROLLBACK IMMEDIATE (pause) DROP DATABASE foo But...

How to find 3rd max value of a column using MAX function in sql server?

Yesterday i had a question in an interview which i thought i could find answers here in SO... How to find 3rd max value of a column using MAX function in sql server? Consider the column to be Wages 20000 15000 10000 45000 50000 ...

How to create database project from existing SQL Server database?

By using VS TFS Database Edition 2008, how to create dbproject from an existing SQL SERVER database? ...

How to get total number of hours between two dates in sql server?

Consider two dates 2010-03-18 22:30:45 and 2010-03-19 03:30:15 .... How to get the number of hours and minutes in between the two dates in sql server..... ...

SQL Server Export Data failing

I am trying to export a table from SQL Server 2005 using the Import/Export Wizard. I've had no problems exporting data and have successfully exported from 5 tables before, but I am now getting this error: Error 0xc0209029: Data Flow Task: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "Destination Input" (114)" faile...

SQL Server 2005 - Understanding ouput of DBCC SHOWCONTIG

I'm seeing some slow performance on a SQL Server 2005 database. I've been doing some research regarding SQL Server performance but I'm having difficulty fully understanding the output of SHOWCONTIG and would be very grateful if someone could have a look and offer some suggestions to improve performance. TABLE level scan performed. Pag...

put today + 3 working days (as default value) in a Sql datetime field

Hi, i want to set the default value in a sql server 2005 datetime field to today + 3 working days. ...

How can I use a subquery as alias in SQL Server 2005

This is my code. Its giving me an error. select b.bill_no as 'Bill Number', (select descript from SALE_TERMS where STERMS_CODE='99')=b.[99] from BILLDET as b ...

Can Sql Server 2005 Pivot table have nText passed into it?

Right bit of a simple question can I input nText into a pivot table? (SQL Server 2005) What I have is a table which records the answers to a questionnaire consisting of the following elements for example: UserID QuestionNumber Answer Mic 1 Yes Mic 2 No Mic 3 Yes Ste...

How to select the value of the xsi:type attribute in SQL Server?

Considering this xml document: DECLARE @X XML (DOCUMENT search.SearchParameters) = '<parameters xmlns="http://www.educations.com/Search/Parameters.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; <parameter xsi:type="category" categoryID="38" /> </parameters>'; I'd like to access the value of the attribute "type". Ac...

Remove and Replace multiple chars ( spaces, hyphen, brackets, period) from string in sql

+39 235 6595750 19874624611 +44 (0)181 446 5697 +431 6078115-2730 +1 617 358 5128 +48.40.23755432 +44 1691 872 410 07825 893217 0138 988 1649 (415) 706 2001 00 44 (0) 20 7660 4650 (765) 959-1504 07731 508 486 please reply by email dont have one +447769146971 Please see the above given phone numbers. I need to replace all spaces, hyphe...

SQL Server 2005 database design - many-to-many relationships with hierarchy

Note I have completely re-written my original post to better explain the issue I am trying to understand. I have tried to generalise the problem as much as possible. Also, my thanks to the original people who responded. Hopefully this post makes things a little clearer. Context In short, I am struggling to understand the best way to...

Split query result by half in TSQL (obtain 2 resultsets/tables)

I have a query that returns a large number of heavy rows. When I transform this rows in a list of CustomObject I have a big memory peak, and this transformation is made by a custom dotnet framework that I can't modify. I need to retrieve a less number of rows to do "the transform" in two passes and then avoid the memory peak. How can ...

Problem with SqlServer 2005 when opening connections

I have a Winforms application and I use EntLib to connect to a SQL Server 2005 DB. The application is working ok, but sometimes, and lately more often, we have started receiving this error from the db when opening the connection: A connection was successfully established with the server, but then an error occurred during the login pr...

Problems when importing from Access database to Sql Server through Access queries

Hi, I have an Access database (in Access 2003) with several tables, and data must be imported to Sql Server 2005. Access data does not have the same structure as sql server database, so I created various queries which transforms it to format needed by Sql Server. Basically for each table in sql server I have two queries: a Select query ...