sql-server

List the queries running on SQL Server

Is there a way to list the queries that are currently running on MS SQL Server (either through the Enterprise Manager or SQL) and/or who's connected? I think I've got a very long running query is being execute on one of my database servers and I'd like to track it down and stop it (or the person who keeps starting it). ...

Breaking up SQL script

I am writing a rather long SQL script that is running close to 2000 lines of code. Since it becomes really difficult to comprehend a long script, I would like to break it up into logical units and separate them out in other SQL files. What would be the best way of doing this? Would each logical unit need to be a Stored procedure? maybe ...

When are shared read locks released?

When SQL Server Books online says that "Shared (S) locks on a resource are released as soon as the read operation completes, unless the transaction isolation level is set to repeatable read or higher, or a locking hint is used to retain the shared (S) locks for the duration of the transaction." Assuming we're talking about a row-level ...

SQL Server: Extracting a Column Into a Table

I have a table with a column that I want to extract out and put into a separate table. For example, lets say I have a table named Contacts. Contacts has a column named Name which stores a string. Now I want to pull out the names into another table named Name and link the Contact.Name column to the Id of the Name table. I can only use ...

Reporting Services Chart - Custom Axis Label

Hello, I have a SQL Server Reporting Services (2008) chart (error chart). The X-axis has date intervals 1/1/2009, 2/1/2009, etc. The Y-axis has numeric intervals of 50. Values on the Y-axis are 0, 50 and 100. However, instead of displaying 0, 50 and 100 i would like to display "Small","Medium" and "Large" respectively. Does anyone know ...

How to refactor a trigger that uses the inserted and deleted tables, to move common code to a stored procedure

I have a trigger that will be dynamically created, as it will be attached to a view that is also dynamically generated. I don't want my stored procedure to have the entire trigger within it, so I would like to move most of it to a stored procedure, but I won't know the fields in the inserted and deleted tables. The trigger is about 90 ...

Using integration service, how can I copy a record, with all the records that the main record has a foreign key relationship to

I am working on creating the necessary views, triggers and stored procedures so I can make it easier for people to use Integration Service to copy data to and from our database, which is an entity-attribute-value schema, so the foreign key relationships are not always explicitly stated in the schema, but in my view I can hopefully make i...

SQL Server Linked Server query running out of memory

I have a DBF file on a network share that I'm trying to select into a SQL Server table. This query: SELECT * FROM OPENQUERY(MyLinkedServer, 'SELECT * FROM DP') ... throws this error: OLE DB provider "MSDASQL" for linked server "MyLinkedServer" returned message "[Microsoft][ODBC Visual FoxPro Driver]Not enough memory for file map.". ...

Unable to edit or delete schedule reports in SSRS

I'm currently getting the following error when editing and deleting scheduled reports in SSRS: "Only members of sysadmin role are allowed to update or delete jobs owned by a different login." I've tried changing the owner of the jobs to the Service account used by SSRS, I've added that users as a sysadmin and I've checked the user and p...

Creating SQL Server Stored Procedure from Access 2007 - change schema

I have an Access 2007 Project with a SQL Server 2005 backend. However, when creating a new stored procedure from within Access, it comes up with an error: ADO error: The specific schema name DOMAIN\username either does not exist or you do not have permission to use it How can you create a stored procedure using the 'dbo' schema ins...

Help with Multiple group by SQL Server Query

I'm having some troubles to retrieve data from 2 tables with using multi "group by". Below is 2 tables for example and the result I would like to have from my query. PrdID Name KG ------------------ 1 Hals 10 2 Hals 3 3 Kugel 4 4 Kugel 10 5 Hals 12 6 Kugel 11 7 Hals 12 8 ...

Distinct on each column

I need to select 3 columns from a table, but I need each value from any column to be unique in the resultset for this column. This query: SELECT DISTINCT TOP 10 a, b, c FROM x will return 10 distinct sets. How do I do it? ...

TSQL query to concatenate and remove common prefix

I have some data id ref == ========== 1 3536757616 1 3536757617 1 3536757618 and want to get the result 1 3536757616/7/8 so essentially the data is aggregated on id, with the refs concatenated together, separated by a slash '/', but with any common prefix removed so if the data was like id ref == ========== 2...

Open Source Database Proxies?

Does anyone know of an open source database proxy where it can serve as an intermediary between a closed-source client application and either a SQL server and/or Oracle database? ...

how to using smo library in c++

Hi I am trying to list all the instances of sqlserver using c++ in vs2005. How to do this using smo library in c++? give me code example. Thanks in advance.. ...

How to efficiently store and manage images in SQL Server 2005

I want to insert my product's image into a database and then want to get those image on request. please suggest. ...

Order by integer with blank fields at the bottom.

Hi, We're rewriting our CMS at the moment and we want our clients to be able to re-order items in a table using a "position" field. So, if they mark an items as position 1 it goes at the top, then position 2 underneath it etc. The problem is that we don't want to them to have to fill in a position every time, only if they want to re-or...

Problem with Unit test and SQL database Connection

I am having a problem with a unit test I have created. First time doing this so I am not sure why I am getting this error <DeploymentItem("ETDS.exe")> <DataSource("System.Data.SqlClient", "Data Source=Foo;Initial Catalog=FooDB;Integrated Security=True", "User_Names", DataAccessMethod.Sequential)> <TestMethod()> _ Public Sub ValidateUser...

How do I find out what is hammering my SQL Server?

My SQL Server CPU has been at around 90% for the most part of today. I am not in a position to be able to restart it due to it being in constant use. Is it possible to find out what within SQL is causing such a CPU overload? I have run SQL Profiler but so much is going on it's difficult to tell if anything in particular is causing it....

SQL Server 2008 Performance: No Indexes vs Bad Indexes?

Hey guys, i'm running into a strange problem in Microsoft SQL Server 2008. I have a large database (20 GB) with about 10 tables and i'm attempting to make a point regarding how to correctly create indexes. Here's my problem: on some nested queries i'm getting faster results without using indexes! It's close (one or two seconds), but i...