sql-server-2005

Monitoring the progress of an SQL query in SQL SERVER

Hello, I saw a similar question which asked how to monitor the progress of a backup / restore operation: http://stackoverflow.com/questions/152447/is-there-a-sql-script-that-i-can-use-to-determine-the-progress-of-a-sql-server-ba I would like to know if there's a similar query / way to see how much time the query has left until it will...

insert data into several tables - possibly using OUTPUT - sql server 2005

Dear all, I would like to insert data from a file into the table Division of this model which is very much simplified: create table Statements ( Id INT IDENTITY NOT NULL primary key (Id) ) create table Item ( StatementFk INT not null, ItemNameFk INT not null, primary key (StatementFk) ) cr...

varbinary to string on SQL Server

How to convert a column value from varbinary(max) to varchar to read.. ...

SQL: Best approach to Select and Insert from multiple tables

What do you guys think would be the best approach here? I have about 30 SQL tables that is basically referenced by a [lookup] table. I have to do an insert in another table [FinalTable] for each row in the [lookup] table. Now the [lookup] table looks something like this. ID, Zipcode, tableID 1, 60453, 1 2, 90210, 1 3, 60453, ...

In SQL Server 2005 is there a way to set the default schema to anything other than dbo when the user has admin rights?

I am using SQL Server 2005 with Windows authentication. My login has administrator rights. For my login I have a user mapped to a database with the default schema set to "my_schema". My login is not the owner of the database. When I log on though, and try to execute a simple select statement on a table in "my_schema" without specifyi...

SQL Server - Need to gt back data based on nested rank

We have a feature that allows us to create SQL to get back data from one table based on a nested query that filters records based on matching criteria from another table. Now, we need to be able to get back data from the first table based on the top x records of the nexted query, rather than all matching records. For Example we want s...

Calculate time difference (only working hours) in minutes between two dates

I need to calculate the number of "active minutes" for an event within a database. The start-time is well known. The complication is that these active minutes should only be counted during a working day - Monday-Friday 9am-6.30pm, excluding weekends and (known) list of holiday days The start or "current" time may be outside working ho...

How to build a query by passing the columname and columnvalue as parameter using LINQ

Hi All, We tried using the below code snippet but showing the syntax error. var query = (from def in entity.Defect.Where("Owner == @0", "rochs") select def).ToList(); Thanks in Advance ...

Sql Query Optimization Tool

Hi I need to optimize my large queries for fast performance. Is there any free tool for optimizing sql queries for sql server 2005? ...

How can I ensure a read only user is created for every new database in SQL server 2005?

We create multiple databases in sql server 2005. I would like to make sure that every new database that is created has a specific read only account when it gets created. I know there is a way to write code to do this, but is there a way we can set up a database template of some sort so every time a new database is created the account i...

"Distinct" column in SQL query

SELECT id, EmpNo FROM EmployeesTable EmpNo can be the same for 1 or more records in the results of the above query. I now want to add another column derived from EmpNo(lets call it EmpNo2) but only returning distinct values of EmpNo. For example if the above query returns 100 records but there are 69 distinct EmpNo values and i...

Handling 100's of 1,000,000's of rows in T-SQL2005

I have a couple of databases containing simple data which needs to be imported into a new format schema. I've come up with a flexible schema, but it relies on the critical data of the to older DBs to be stored in one table. This table has only a primary key, a foreign key (both int's), a datetime and a decimal field, but adding the coun...

Sql Server 2005 - Add partition scheme to a non partitioned table

I have a table that has more than 50 million records and which does not have any partition. But now i want to add a partition scheme to this table. This table has a primary key. But i want to partition it using another int column. How can i do it? ...

IP Access to SQL Server

Hello, We have a Windows VPS server using SQL Server 2005 for our e-commerce site. A while back we were suffering from attempts to access the database remotely so someone made changes so that only the IP of the server itself could access data. That was about 18 months ago and everything has been fine since. However, we now have a seco...

T-SQL Distinct column problem when trying to filter duplicates out

I have the following data COL-1 COL-2 1 0TY/OK 1 0TY/OK 1 0TY/OK 1 0TY/OK 1 0TY/OK 2 2KP/L 2 2KP/L 2 2KP/L 2 2KP/L 2 2KP/L 3 7U5/2M 3 7U5/2M 3 7U5/2M 3 7U5/2M And i want to construct a select query to ret...

Methods to enable Sql Notification Services

Hi All What is the difference in the following mentioned things, are these used for differnet purposes or are they used collectively for some functionality, can anyone please differentiante among these based on their functionalities: 1) SqlCacheDependencyAdmin.EnableNotifications(ConnStr) 2) AspNet_RegSql.exe -S "ServerName" -d "...

Grouping parents containing the same set of children

I have this parent-child relationship Paragraph --------- ParagraphID PK // other attributes ... Sentence -------- SentenceID PK ParagraphID FK -> Paragraph.ParagraphID Text nvarchar(4000) Offset int Score int // other attributes ... I'd like to find paragraphs that are equivalent; that is paragraphs tha...

Crippled performance when inserting to fulltext-index table on Sql Server 2005

I'm trying to a big insert of records into a table that is fulltext indexed. I have change tracking set to auto. The records are inserted from another table, in numbers typically about 50,000 at a time. On SQL Server 2008 this takes something like 5 seconds to complete. But running on our live 2005 environment this takes upwards of 10 m...

Providing additional data when selecting distinct rows

I have a table of login events coming from Active Directory. One type of these events are machine logins, which include the IP address of the machine doing the login. This is handy, since it provides a timestamped way to determine what machine was on what IP at a given time. I'm trying to construct a query that'll give me a timestamped l...

sql server 2005 sp3 insufficient memory to run query problem

I am trying to execute a humongous query with close to 200 inner joins on a database. It gives me the following error Msg 701, Level 17, State 123 Line 1 I am running the database on a Dual core 2.7 GHz machine with 2GB of RAM. Is there any way I can get this query to execute? ...