sql-server-2008

How to synchronize two (or n) replication processes for SQL Server databases?

There are two master databases and two read-only copies updated by standard transactional replication. It is needed to map some entity from both read-only databases, lets say that A databases contains orders and B databases contains lines. The problem is that replication to one database can lag behind replication of second database, a...

How to use a value from one stored procedure in another?

I have the following statement in a Stored Procedure: DECLARE @Count INT EXEC @Count = GetItemCount 123 SELECT @Count Which calls another stored procedure with the following statement inside: SELECT COUNT(Item) FROM tblItem WHERE ID = @ID However when I test the call the EXEC outputs the value correctly but it is not assigned to th...

how to show only even or odd rows in sql server 2008 ?

hi i have a table MEN in sql server 2008 that contain 150 rows. how i can show only the even or only the odd rows ? thank's in advance ...

deadlock when SQL Server transaction log ever-increase?

Hello everyone, I am using SQL Server 2008 Enterprise. I have tried that if I set SQL Server transaction log to ever increase for the related database (with no backup settings), then a single delete statement of this stored procedure will cause deadlock if executed by multiple threads at the same time? Any ideas why? For the delete sta...

"Unspecified error" when trying to create a table from SSMS 2005 on a SQL Server 2008 DB

I have just installed SP3 for SSMS 2005 so that I can connect to 2008 databases. I can now connect fine and even create databases, but I get "Unspecified error" when I try to create a new table. ...

SubSonic 2.x now supports TVP's - SqlDbType.Structure / DataTables for SQL Server 2008

For those interested, I have now modified the SubSonic 2.x code to recognize and support DataTable parameter types. You can read more about SQL Server 2008 features here: http://download.microsoft.com/download/4/9/0/4906f81b-eb1a-49c3-bb05-ff3bcbb5d5ae/SQL%20SERVER%202008-RDBMS/T-SQL%20Enhancements%20with%20SQL%20Server%202008%20-%20Pra...

SQL trigger for audit table question

I am writing a trigger to audit updates and deletes in tables. I am using SQL Server 2008 My questions are, Is there a way to find out what action is being taken on a record without going through the selection phase of the deleted and inserted tables? Another question is, if the record is being deleted, how do I record within the au...

SQL Server 2008 Management Studio Basic and Express

Hi, what are the differences between the SQL Server 2008 Management Studio BASIC and SQL Server 2008 Management Studio EXPRESS? Do they are the same? THANKS! ...

Query performs poorly unless a temp table is used

The following query takes about 1 minute to run, and has the following IO statistics: SELECT T.RGN, T.CD, T.FUND_CD, T.TRDT, SUM(T2.UNITS) AS TotalUnits FROM dbo.TRANS AS T JOIN dbo.TRANS AS T2 ON T2.RGN=T.RGN AND T2.CD=T.CD AND T2.FUND_CD=T.FUND_CD AND T2.TRDT<=T.TRDT JOIN TASK_REQUESTS AS T3 ON T3.CD=T.CD AND T3.RGN=T.RGN AND T3.TASK ...

Repeatedly execute a stored procedure

I have a situation where I need to repeatedly execute a stored procedure Now this procedure (spMAIN) has a cursor inside which looks for a value from a table as T1,which has the following structure ID Status ---- -------- 1 New 2 New 3 success 4 Error now the cursor looks for all rows with a status of 'New' Now...

Error connecting to SQL Server 2008 with Django

I am using django-mssql and SQL Server 2008, but I found that it always errors when I do some commands,for example: python manage.py syncdb the error is below: raise OperationalError(e, "Error opening connection: " + connection_string) sqlserver_ado.dbapi.OperationalError: (com_error(-2147352567, '\xb7\xa2\xc9\xfa\ xd2\xe2\xcd\xe2\xa...

LINQ with Stored Procedures for XML Raw

I am new to LINQ and trying to learn it. I have a stored proc which returns XML Raw and I need to call this proc using VB.NET and LINQ... ...

Store latitudes and longitudes in database for proximity/radius search using Google Maps API, .NET and SQL Server

What is the approach for storing the latitudes and longitudes for multiple addresses as a one time set up. I need to find the nearby stores using Google Maps and I have to get the latitudes and longitudes of all the available stores. As the data is huge and may increase or change in future, can anyone suggest an approach taking performan...

Is it possible to inspect the contents of a Table Value Parameter via the debugger?

Does anyone know if it is possible to use the Visual Studio / SQL Server Management Studio debugger to inspect the contents of a Table Value Parameter passed to a stored procedure? To give a trivial example: CREATE TYPE [dbo].[ControllerId] AS TABLE( [id] [nvarchar](max) NOT NULL ) GO CREATE PROCEDURE [dbo].[test] @controllerD...

Add a column and update it in same stored procedure in SQL Server 2008

if I have a stored procedure say CREATE PROCURE w AS ALTER TABLE t ADD x char(1) UPDATE t set x =1 Even when it lets me create that stored procedure (if I create it when x exists), when it runs, there is an error on the UPDATE statement because column x doesn't exist. What's the conventional way to deal with this, it must come up a...

How to force a SQL Server 2008 database to go Offline

How do I force my Database to go Offline, in no regards to what or who is is already using it? I tried: ALTER DATABASE database-name SET OFFLINE; But it's still hanging of 7 min. I want this because I need to test the scenario. If it's even possible? ...

Incorrect value for UNIQUE_CONSTRAINT_NAME in REFERENTIAL_CONSTRAINTS

I am listing all FK constraints for a given table using INFORMATION_SCHEMA set of views with the following query: SELECT X.UNIQUE_CONSTRAINT_NAME, "C".*, "X".* FROM "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" AS "C" INNER JOIN "INFORMATION_SCHEMA"."REFERENTIAL_CONSTRAINTS" AS "X" ON "C"."CONSTRAINT_NAME" = ...

Fast insert relational(normalized) data tables into SQL Server 2008

Hello All, I'm trying to find a better and faster way to insert pretty massive amount of data(~50K rows) than the Linq that I'm using now. The data I'm trying to write to a local db is in a list of ORM mapped data serialized and received from WCF. I'm keen on using SqlBulkCopy, but the problem is that the tables are normalized and are a...

Pass table as parameter to SQLCLR TV-UDF

We have a third-party DLL that can operate on a DataTable of source information and generate some useful values, and we're trying to hook it up through SQLCLR to be callable as a table-valued UDF in SQL Server 2008. Taking the concept here one step further, I would like to program a CLR Table-Valued Function that operates on a table of ...

How do we setup a remote Standby / Read-Only database to accept Log Shipping?

We have two SQL 2008 servers on different networks that will soon have a VPN connecting them. Soon is 2-3 weeks. If that were in place now we could easily setup Transaction Log Shipping (or other method) of keeping the destination (Standby / Read-Only) database up to date. How do we setup the LSRestore_ job on that destination database w...