sql-server

What’s the best way to import an Excel-file to SQL Server on a 64 bit Windows platform in ASP.NET?

What's the best/smoothest solution to import an Excel-file to SQL Server, on a 64 bit Windows system? What I'm specifically after is to import an Excel 97-2003 file, to a SQL 2005 database, from an ASP.NET/C# page. The import data will demand users to use a "template", so the data looks the same every time. Previously the system has us...

How can I get a batch at a time of all the rows in a sql table?

I have a table with 40 million rows. I want to pick up about 2 million at a time and "process" them. Why? Cos processing processing 10million+ rows degrades performance, and often times out. (I need this to work independant of data size, so i cant just keep increasing the time out limit.) Also, I'm using SQL Server. ...

SQL Server Prevent Scripts Being Run on the Wrong Instance...

This is less of a programming question and more of a suggestions for tools one :-) I'm looking for a way to prevent scripts being accidentally run on the wrong sql server instance, ie so you don't run that script for clearing down customers in your development environment on the live/production environment. What I'm basically after is ...

Generic error when trying to save data

Hi all, we have just experienced a weird error on our applications connecting to a clustered Sql Server 2000: both our .NET applications (ADO.NET) and C++ (ADO) application get an error which we cannot explain. All the applications can connect to the database, can read data from it but cannot write data on it, receiving a "Generic networ...

Clustered primary key on unique identifier ID column in SQL Server

If your ID column on a table is a unique identifier (Guid), is there any point creating a clustered primary key on the ID column? Given that they are globally unique, how would the sorting work? ...

get date by weekOfYear

Hello, I need Week-Start-Date and Week-End-Date for particular Week number in a year (vb.net or SQL Server) For example, if weeknumber=1 and year 2009, I should get: StartDate=1/1/2009 EndDate=1/3/2009 if weeknumber=2 and year 2009, then: StartDate=1/4/2009 EndDate=1/10/2009 Actually I got week number by using datepart(wk, Date) in...

Can a MS SQL stored procedure look up it's own name?

Is there any way within a stored procedure for it to reference it's own name? Say I want it to print it's own name, but not to physically type the name in the stored procedure. Is there any cheater way to get the name or id from within the procedure itself without using the actual name to find the information? ...

Return sql query results in separate columns sorted vertically.

How can I rewrite the query "select col1 from tbl1" so it splits the results into three columns - each column sorting the results vertically? So if the data I'm getting back is: aaa bbb ccc ddd eee fff ggg I need the query to return it as: aaa ddd ggg bbb eee ccc fff Is this possible? Thanks ...

Re-runnable SQL Server Scripts

What are the best practices for ensuring that your SQL can be run repeatedly without receiving errors on subsequent runs? e.g. checking that tables don't already exist before creating them checking that columns don't already exist before creating or renaming transactions with rollback on error If you drop tables that exist before cr...

how to detect all sql server instances from studio?

There are multiple instances of SQL Server 2005 installed on a box. Is there a T-SQL query I can run from Studio that will detect these other instances and their names? ...

Using both a GUID and an auto-incrementing integer

I've been investigating the use of GUIDs as primary keys in databases. So far, the pros seem to outweigh the cons. However, I see one point where GUIDs may not be what I want. In my application, users should be able to identify objects based on a user-friendly ID. So, for example, if they want to get a specific product without typing in...

How do I extract duplicate records from a table using multiple fields?

I've already checked out the question http://stackoverflow.com/questions/633860/deleting-duplicate-records-using-a-temporary-table and it doesn't quite go far enough to assist me with this question: I have a table of approximately 200,000 address locations hosted on a SQL 2000 Server. This table has a huge problem with duplicate data in...

Inner joining UDF on SQL Server

Hello, i have a table valued function that does a complex query and returns a table (UDF1), and then I have another table that has a bunch of rows that can be used to reduce the output from this UDF Is it possible to join these two and pass columns from the table as arguments to the UDF ? like SELECT * FROM UDF1(TBL1.Column1, TBL1....

Dealing with duplicated data in SQL Server

I have a large SQL server table that looks something like this: ImageId int Page int FSPath varchar(256) ImageFrame int ... The table stores an entry for each page of a number of image files. This is done to enable the table to represent images where each page is represented by a different file, and multi-page image files that conta...

Most Efficient (Fast) T-SQL DELETE For Many Rows?

Our server application receives information about rows to add to the database at a rate of 1000-2000 rows per second, all day long. There are two mutually-exclusive columns in the table that uniquely identify a row: one is a numeric identifier called 'tag' and the other is a 50character string called 'longTag'. A row can have either a ...

What is the best practice for role security for an Intratnet ASP.NET/SQL2K5 environment?

Our current Intranet environment is a little outdated. The current stack has ASP.NET 1.1/2.0 applications that are querying against a SQL 2000 database. For role security, there are user groups on the servers that users are added into (so you need to be added into the group on the test and production machine). These user groups are syn...

SQL Server 2005 - Trigger Loop?

I am using triggers for the first time. If I update a field in a table by an update trigger on the same table, with this spark a loop? Does sql server guard against this recursive behavior? Thanks ...

How do you search for a & (ampersand) in the tsql contains function?

I have a table T which has a column C which contains text that have the character & within it, but if I do the following query, it returns nothing, although I may have 10 rows. SELECT * FROM T WHERE Contains(C, 'a&b') ...

Why is SQL Server losing a millisecond?

I have a table structured like this: CREATE TABLE [TESTTABLE]( [ID] [int] IDENTITY(1,1) NOT NULL, [DateField] [datetime] NULL, [StringField] [varchar](50), [IntField] [int] NULL, [BitField] [bit] NULL ) I execute the following code: BEGIN INSERT INTO TESTTABLE (IntField,BitField,StringField,DateField) VALUES ('1...

Why am I getting this database connectivity error in SQL Server?

I'm a beginner in Database programming and am having trouble connecting to my database. I use the following code for connectivity. public class dbOpnClse { SqlConnection con = new SqlConnection(); public SqlConnection openConnection() { con.ConnectionString ="server=SERVERNAME;database=Test;uid=###;pwd=#####"; ...