sql-server

How to do a union across multiple Sql Server?

I have two Sql Servers (two distinct databases, (i.e. two machines)) with the same structure. Is there a way to do a SELECT * FROM (SELECT * FROM TableOnServerA Union SELECT * FROM TableOnServerB)? Thanks ...

SqlDataReader - How to convert the current row to a dictionary

Is there an easy way to convert all the columns of the current row of a SqlDataReader to a dictionary? using (SqlDataReader opReader = command.ExecuteReader()) { // Convert the current row to a dictionary } Thanks ...

Efficient SQL procedure to get data from name value pair table into DataSet?

Using SQL Server, have a name value pair table. Each row is basically userid, contentid, sectionid, parameter, value. So there is data I want to display in a table such as user information. Each bit of information is in it's own row, sow how do I get it into a DataSet for use in a Repeater? Can I somehow merge the rows into one? So I can...

How can I find out when a Sql Database field gets modified?

One of my database fields in a table is getting modified by some piece of code. I just can't figure out where! So, I was wondering if there's a way I can find out. I'm using SQL 2008. Can Profiler be used to find out if a particular field is getting updated? How? What about a Trigger? If using a trigger (eg. on UPDATE) can you determ...

saving the FOR XML AUTO results to variable in SQL

select @[email protected]('*') for xml raw,type Above statement will generate following alert: Msg 6819, Level 16, State 3, Line 2 The FOR XML clause is not allowed in a ASSIGNMENT statement. ...

Is there any way to find out the size / sizes of your database tables?

Hi folks, i've got around 10 tables in my sql 2008 server. Currently, my mdf is around 3.5Gig. (I also have some binary data in some of the tables). So, I'm wondering if there's a way i could see which tables are the biggest in size. Is this possible? Maybe it's an index or FTS catalog instead? ...

SQL Server Replication, How to Synch. a Subscriber gone offline

Hi All, We are using SQL Sever 2005 replication for out application. Every thing is working fine without any problems. However, recently we ran into a situation to which I have no solution. We use merge replication with the publisher(sql server 2005) in one geography and the subscribers(sql server 2005 express) in multiple other geogra...

Using C# assembly in SQL Server

I've got a c# class library that I call from an asp.net application. The assembly calculates grades for students and performs calculations using datatables and such. How can I use this assembly in SQL Server 2005 and call it once for each record in a database table? I want to re-use functionality and avoid writing the thing in T-SQL. ...

Scheduled Task or Service for Routine Database Job in C#?

I've got a web server and a database server, and I'd like to run a job that uses an existing C# DLL to access the database and perform some calculations. Is the simplest method to create a console app in C# and schedule it on the web server (app server) to run against the DB server? I see SSIS as an option, but I don't know that well, ...

Looping through Dataset

Hi All, While looping through a Dataset which code snippet should I use, should I go for 2 foreach or a single for snippet1: for (int i = 0; i < ds.Tables["TableName"].Rows.Count; i++) { // My Code } snippet2: foreach (DataRow dr in ds.Tables["TableName"].Rows) { foreach (DataColumn ...

can I attach database on different sql instances at the same time?

I have sql database stored on a shared netwrok drive , after set of configurations I can attach this database over the network on sql server 2008 instance. But I want to attach the same database on different machine that contains different sql instance (I think logically there is no data corruption as I want it to be reading only). So ...

Making my SSIS package portable - how to do this?

I know how to create SSIS packages and getting my data source and destinations. But what will i have to do in my package if i want to make it portable in the sense where i can change the source and destination connection strings when i move my package onto another PC? Thanks in advanced! ...

Fastest way to script generation SQL server DB schema for hashing

I'd like to ge the whole SQL schema for a DB, then generate a hash of it. This is so that I can check if a rollback script returns the schema to it original state. Is there a SP I can use or some other cunning method? I'd like it to be as fast as possible. ...

How to connect from ruby to MS Sql Server

Hi Crowd! I'm trying to connect to the sql server 2005 database from *NIX machine: I have the following configuration: Linux 64bit ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux] important gems: dbd-odbc (0.2.4) dbi (0.4.1) active record sql server adapter - as plugin ruby-odbc 0.9996 (installed without an...

Transaction with Read Committed Isolation Level and Table Constraints

Does table constraints execute in the same transaction? I have a transaction with Read Committed isolation level which inserts some rows in a table. The table has a constraint on it that calls a function which in turn selects some rows from the same table. It looks like the function runs without knowing anything about the transaction ...

Is there a way to multithread a SqlDataReader?

I have a Sql Query which returns me over half million rows to process... The process doesn't take really long, but I would like to speed it up a little bit with some multiprocessing. Considering the code below, is it possible to multithread something like that easily? using (SqlDataReader reader = command.ExecuteReader()) { while (r...

SQL Case statement Syntax

I am trying to write a select statement that will select a number of fields including an email field. There are 3 email fields available in this table which can sometimes contains null values. I wan to look at 3 fields; [email address1], [email address2], [email address3] and basically what I want to do is if [email address3] is null t...

How can a LEFT OUTER JOIN return more records than exist in the left table?

Hi, I have a very basic LEFT OUTER JOIN to return all results from the left table and some additional information from a much bigger table. The left table contains 4935 records yet when I LEFT OUTER JOIN it to an additional table the record count is significatnly larger. As far as I'm aware it is absolute gospel that a LEFT OUTER JOIN ...

Crazy SSIS Component Arrangements

Is there a way to tell Visual Studio 2005 to not rearrange your SSIS package components when you close and re-open the .dtsx? VS2005 always moves my components around in the Control Flow tab and adjusts the flow pointers to seemingly random positions and it gets quite irritating. Anyone know the setting (if any) to stop this? Thanks in ...

How to call Stored Procedure in a View?

How would I call a Stored Procedure that returns data in a View? Is this even possible? ...