sql-server

Why do I get "The server encountered a stack overflow during compile time" error is SQL Server 2000 Sp4

I am trying to have around 6290 'AND' conditions in this query. I get the same for around 11945 'OR' conditions. Exception details: The server encountered a stack overflow during compile time. at System.Data. lClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnecti...

How do I take a day of the year and 'bucket it' into weeks of the year in Microsoft SQL? Used in manufacturing scenarios for material requirements

I have a need to create a gross requirements report that takes how much supply and demand of a item in inventory from a start date onwards and 'buckets' it into different weeks of the year so that material planners know when they will need a item and if they have enough stock in inventory at that time. As an example, today’s date (repor...

SQL Query Advice - Get Previous Item

Hi, I asked the opposite question here, now I am faced with another problem. Assume I have the following tables (as per poster in previous post) CustID LastName FirstName ------ -------- --------- 1 Woman Test 2 Man Test ProdID ProdName ------ -------- 123 NY Times 234 Boston Globe ProdID IssueID PublishDate ...

What are the downsides of sqlserver 2008 (vs 2005)

I'm starting a new project and I'm considering using sqlserver 2008. I've had a lot of trouble getting teamsystem to work with it, and I'm wondering if sql server 2008 is widely used in productions environment yet. What whould you choose? How do you compare sqlserver 2005 and 2008? EDIT : I agree about the obvious and general tradeoff...

How do I sort query results by keyword occurrence in column? (SQL Server Full-Text)

How do I sort the query results by keyword occurrence in column? I'm using SQL Server 2008 with Full-text indexing. ...

Msbuild task to restore SQL Server database

What is a quick example / demo of an msbuild task to delete then restore a database and also maybe run any .sql files against the restored database? ...

Process dimension fails with message "A FileStore error from WriteFile occurred"?

Hi, I am trying to process a dimension using SQL Server 2005 Analysis Services. This has worked in the past without problems but recently fails. The dimension is hierarchical using 4 columns from a single table (the entire cube uses a single table). The error message received (regardless if I process the entire cube or the dimension, w...

SQL Server 2008 Maintenance Plans Failing because Database is in use

I've created a couple of maintenance plans on our Sql Server 2008 databases that perform back-ups (full and differential) to run overnight, but they keep failing with a message saying the database is currently in use. We typically have little to no traffic during the times the maintenance plans are scheduled to run so I'm not sure why I...

How to limit SQL queries CPU utilization?

After a large SQL Query is run that is built through my ASPX Pages I see the following two items listed in sql profiler. Event Class TextData ApplicationName CPU Reads Writes SQL:BatchCompleted Select N'Testing Connection...' SQLAgent - Alert En...

SQL Server / MySQL / Access - speeding up inserting many rows in an inefficient manner

SETUP I have to insert a couple million rows in either SQL Server 2000/2005, MySQL, or Access. Unfortunately I don't have an easy way to use bulk insert or BCP or any of the other ways that a normal human would go about this. The inserts will happen on one particular database but that code needs to be db agnostic -- so I can't do bulk...

How can I auto-backup a SQL Server Express database?

I've deployed MS Sql Server Express edition on a server with a database that's updated daily. It is important that I have regular backups of the database, preferably daily. But I can't hope to do this manually everyday. How can I have auto-backups of my databases on that server? A system that will preferably upload these databases to a F...

How to create a stored procedure with dynamic from clause

I have a problem with an application which uses the same stored procedure over and over again to populate people information in dropdown lists. The problem is that sometimes people aren't there anymore as the data changes. I have two views I can use to select from, but I want to dynamically change which view is being used based on the st...

Create Diagram in SQL Server Enterprise Manager (SQL 2000)

What is the lowest permission level I need on a user to be able to create diagrams in SQL Server Enterprise Manager? I'm currently set as data reader and I am unable to create diagrams. (I wouldn't expect to be able to at this permission level) ...

Indexing strategy on table

I have an SQL Server 2005 table named 'EventTable' defined as such: EventID, EventTypeCode, EventStatusCode, EventDate Currently the table has a clustered index on the primary key 'EventID', there are no other indexes currently EventTypeCode and EventStatusCode columns are CHAR(3) (examples are 'NEW', 'SEN', 'SAL') and are foreign key...

SQL Server UNION - What is the default ORDER BY Behaviour

If I have a few UNION Statements as a contrived example: SELECT * FROM xxx WHERE z = 1 UNION SELECT * FROM xxx WHERE z = 2 UNION SELECT * FROM xxx WHERE z = 3 What is the default order by behaviour. The test data I'm seeing essentially does not return the data in the order that is specified above. I.e. the data is ordered, but I wan...

Different execution plan when executing statement directly and from stored procedure

While developing a new query at work I wrote it and profiled it in SQL Query Analyzer. The query was performing really good without any table scans but when I encapsulated it within a stored procedure the performance was horrible. When I looked at the execution plan I could see that SQL Server picked a different plan that used a table sc...

SQL Server - Using a column alias in a subquery

I have the following query which works fine with MySQL but refuses to work with SQL server: SELECT table1.someField AS theField, COUNT(table2.someField) / (SELECT COUNT(someField) FROM table1 WHERE someField = theField), FROM table1 LEFT JOIN table2 ON table1.someField = table2.someField SQL Server doesn't seem to like the ali...

What security benefits are provided by using stored procedures to access data?

I have seen some guidance which recommends that you secure a database by layering all data access through stored procedures. I know that for SQL Server, you can secure tables, and even columns against CRUD operations. For example: --// Logged in as 'sa' USE AdventureWorks; GRANT SELECT ON Person.Address(AddressID, AddressLine1) ...

Can SQL Server Replication include the source dbid in the replicated data?

Let's say I have DatabaseA with TableA, which has these fields: Id, Name. In another database, DatabaseB, I have TableA which has these fields: DatabaseId, Id, Name. Is it possible to setup a replication publication that will send: DatabaseA.dbid, DatabaseA.TableA.Id, DatabaseA.TableA.Name to DatabaseB.TableA? Edit: The reason I'm ...

Sql Server management studio how to auto capitalize

Is there any FREE "build-in" way to capitalize the "keywords" in the SQL 2005/2008 management studio when you write a sql query? i.e truncate table x should be automatically changed to: TRUNCATE TABLE x ...