sql-server

What is the best way to track when table(s) are updated in SQL?

In the past I have just added an field to each table and updated it with GETDATE() on every update/insert. The problem is now I have to keep track of delete too. I was thinking of just having a table that I would update when anything changed and add a trigger to all of the other tables. Ideas??? Thanks! ...

Efficient SQL query for two update and search queries

I have a query like this: SELECT TOP 1 ID, DATA, OTHERINF FROM MYTABLE WHERE DATE = @DATE and after reading the row data and using it I want to update that retrieved row and change one of it's columns (in another transaction). But as you see here i searched for that row twice. Is there anyway that I keep remember the row and do the u...

Does SQL Server Integration Services (SSIS) re-compile C# code every time it's run?

We have a process that is getting data in real time and adding records to a database. We're using SQL Server 2008 Integration Services to run our Extract Transform Load (ETL) process. We download about 50 files from an FTP site, process them and then archive the files. The problem is that the processing is taking about 17s per file even...

SQL Server communication between VirtualBox images

I have a WinXP host with VirtualBox 3.1.2 installed. I have a VirtualBox image called "hydrogen" on which I installed WinXP and MS SQL Server 2005 Express. I have another VirtualBox image called "helium" on which I installed WinXP. I am trying to create a ODBC DSN on "helium" that connects to SQL Server on "hydrogen" but it fails. All o...

Help us fix this sql statement.

SELECT DISTINCT u.UserID, UserLastName, UserFirstName, UserName, Notified, MAX (CycleNumber) as CycleNumber, (CycleCurrentStep) as CycleCurrentStep, MAX (CycleDateReported) as CycleDateReported, max (cycleid) FROM [User] u left join Cycle c on (u.UserID = c.UserID) join UserDivSection us on (u.UserID = us.UserID and us.DivSection...

What is the SQL Server timestamp equivalent in sqlce?

I have some data with a timestamp in SQL Server, I would like to store that value in sqlce with out getting fancy to compare the two values. What is the SQL Server timestamp equivalent in sqlce? ...

SSRS report showing number of appointments per customer per week (layout)

I want to create a report that shows the number of meetings per customer per week in a calendar type of layout. I'm using SQL Server Reporting Services 2005. For simplicity lets say we have only these two tables: Customer Id Name Appointment Id Subject Date What is the most efficient way to produce a report with this layout? ...

SQL Server 2005 Unique constraint on two columns

How do you add a unique constraint in SQL Server 2005 to two columns? So lets say that I have: PK, A, B ... x1 1 1 x2 1 2 x3 2 1 x4 2 2 I should not be able to add another row 'x5' and have the values for A and B be 1,1 as they are already in the database in x1? Ok we managed to get it to work and thanks to OMG. Go to the t...

Getting info about running update query

On Sql Server 2008, I have a slow-running update query that has been working for 3 hours. Is there any way to get any statistics (say, how many rows have changed so far or something else) about this execution (of course, while executing) ? So that I can make a decision between canceling query and optimize it or let it finish. Or else, s...

Pass back original SQL operation row count, after trigger?

I have a piece of legacy VB6 code that is inserting data into a sql server 2000 database table. The code uses the row count returned for various purposes. We recently put a trigger on the table which calls a stored procedure to update another table. It now appears that the VB6 code is picking up the row count returned from the triggered...

SQL Server Group By which counts occurrences of a score

Hi, This might be a bit difficult to explain but I have two columns in my SQL server database which I have simplified... Items ID itemName voteCount score Votes itemID score So, basically I am storing every vote that is placed in one table, but also a count of the number of votes for each item in the item table along with it's averag...

Can SQL Server Compact be used as both a Source and Destination in SSIS?

I'm wondering if SQL Server Compact Edition can be used as both a Source and Destination in an SSIS dataflow. I know I can setup a SQLMOBILE connection manager, and I've found some information that mentions using it as a Destination, but nothing on using it as a Source. What I'm looking to do is to transfer data from one SQL Server Com...

Insert multiple records in one query

I am trying to insert about 100,000 in my SQL Server database. It is really slow when I create 100,000 separate queries, so I tried to insert all these records in one query, it worked for the first few thousands records but then it threw me a timeout error. What would be the fastest way to insert multiple records into database? ...

SSIS transactions with multiple OLE DB commands

I have the following Data Flow task in my SSIS package: It reads a file from an external vendor that has records with a column "change" that cointains A, C or D for add, change and delete. I have to process these in my SQL Server database. The conditional split checks the value of the change column and sends the row off to the appropr...

Automated Filegroup Migration in SQL Server

Recently I've been trying to restructure an old database that was not designed with filegroups (just the default PRIMARY) and, among other things, move a bunch of tables to a new Data filegroup residing on a SAN. I know how to migrate the data: ALTER TABLE MyTable DROP CONSTRAINT PK_MyTable WITH (MOVE TO [MyDB_Data]) ALTER TABLE MyTab...

Recurring calculations in SQL 2008 MDX query

I have an MDX query which returns the following tuples: Dim1A, Dim11, Dim21, Measure1A, Measure11, Measure21 Dim1A, Dim12, Dim22, Measure1A, Measure12, Measure22 Dim1A, Dim13, Dim23, Measure1A, Measure13, Measure23 Dim1A, Dim14, Dim24, Measure1A, Measure14, Measure24 .... .... Dim2A, Dim11, Dim21, Measure2A, Measure11, Measure21 Dim2A, ...

Insert into replicated table fails - identity range check

I'm trying to insert a few thousand rows into a table in a database that is replicated across two servers. From either the publisher or the subscriber, I get the same error: Msg 548, Level 16, State 2, Line 1 The insert failed. It conflicted with an identity range check constraint in database 'XXX', replicated table 'dbo.NODE_ATTRIB_RSL...

SQL huge selection of IDs - How to make it faster?

I have an array with a huge amounts of IDs I would like to select out from the DB. The usual approach would be to do select blabla from xxx where yyy IN (ids) OPTION (RECOMPILE). (The option recompile is needed, because SQL server is not intelligent enough to see that putting this query in its query cache is a huge waste of memory) How...

Drop multple procedures (SQL2005)

Hi, I am curious whether I can drop multiple procedures by simple using "%"? Like: DROP constantName% When I use DROP in the Management studio, it looks like that: /****** Object: StoredProcedure [dbo].[x] Script Date: 02/02/2010 09:36:25 ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[x]') AND t...

SSIS OlEDB Connection manager Error

When am using sequence container to roll back my transactions in execute sql task i am getting the error Connection manager Error: The SSIS Runtime has failed to enlist the OLE DB connection in a distributed transaction with error 0x8004D025 "The partner transaction manager has disabled its support for remote/network transactions.". hav...