sql-server-2008

I am trying to create this table in SQL Server 2008

CREATE TABLE DEPARTMENTS (Department_Id varchar(5) Primary Key NOT NULL, Department_Name char(20) NOT NULL, Manager_Id varchar(5) FOREIGN KEY REFRENCES EMPLOYEES, Location_Id FOREIGN KEY REFRENCES LOCATIONS) GO CREATE TABLE EMPLOYEES (Employee_Id varchar Primary Key NOT NULL, First_Name char(20) NOT NULL, Last_Name char(20) NOT NUL...

Dynamic ORDER BY clause in SQL Server 2008 R2

We have a stored procedure where we want to dynamically let the user choose which column to sort the result by, and in which order (ascending/descending). Currently, we have the following ORDER BY clause, but I'm sure it can be optimized. How? ORDER BY CASE WHEN @OrderBy = 'salvnummer' AND @OrderByDirection = 'DESC' THEN salvnummer ...

How to make SQL Server 2008 R2 trace work like it did in previous versions

I just upgraded from SQL Server 2008 to SQL Server 2008 R2. I went to create a trace, but now it's asking me to pick which options to show in the trace and it doesn't select any of them by default. I'm trying to get a trace that works like it did in previous versions of SQL Server, but I can't figure out which options to check in the T...

SQL Server 2008: No 'release savepoint' for current transaction

Hello, I'm using a PHP database abstraction layer to work with both MySQL and SQL Server. MySQL has a 'release savepoint' statement which SQL Server does not support, and I can't find a comparable statement within T-SQL to use in its stead. Does anybody know of a way around this, or can the lack of functionality be safely ignored? I'd ...

Drop database in SQL Server using wildcard

I have an application that creates a separate database (SQL Server 2008) for each new customer, during testing we end up with a lot of databases called PREFIX.whatever ... I would love a script that would look for all databases starting with PREFIX. and drop them so we can start a clean test cycle. Any help greatly appreciated. ...

Setting date/time in SQL using int values?

I have the following integer type values in a SQL script: @year, @month, @day. Now I want to convert those into a datetime value. Should be easy, right? Well, I just went through the SQL documentation and was very surprised that I couldn't find any way to do this, other than converting to a string and then to a datetime. declare @dt ...

Is there an SQL Server 2008 R2 Developer Edition?

Is there an SQL Server 2008 R2 Developer Edition? I have read there is, but I only see 2008 R1 Developer on Microsoft's website and can't find where to get it. If someone can point me in the right direction I'd appreciate it. I tried Microsoft's sales, but the person I talked to didn't seem to know. If I can't get it now I have to go bac...

simple & fast sql server database backup and restore

Hi, I'm looking for a simple (simplest if possible) way of backing up and restoring a database. I want to do a backup in one state and then after doing some operations get back to the backed up state. Tried Database->Tasks->Back Up... and then Database->Tasks->Restore but I always get an error with: Restore failed for...DBName The t...

SQL Server 2005 and SQL Server 2008 how to make it compatible?

I have in production SQL Server 2005 and in Development SQL Server 2008 Database. I would like to detach database from production create tables, insert data etc. and then attach it back. How make it compatible after I make some changes in SQL server 2008? What is the right way to do it? ...

SQL connection string for importing SO data sump

Hi, I'm trying to use Sam Saffron's program SoSlow (as suggested here) for importing SO's data sump into MS SQL Server 2008. Unfortunately, I have little idea of what I'm doing, and so do not know the Connection String that the program asks for. I have tried the following syntax: Data Source=SHIMI\SQLEXPRESS; Initial Catalog=SO; User I...

How to delete duplicate values for a field in a table with a single query?

I want to delete from a table the entries where it has multiple values for Date field. So say I have Employee table - Id,Name,Date,Points i want to delete the entries with same Date field which should be unique...just to cleanup i need to just keep a single entry for date and delete the rest...maybe keep the recent one if possible....c...

Insert Concurrency Issue - Multithreaded Environment

I have an issue that the same stored procedure is being invoked at exactly the same time with exactly the same paramenters. The purpose of the stored procedure is to fetch a record if it exists or to create and fetch the record if it does not exist. The problem is that both threads are checking the existence of the record and reporting...

How does the WITH statement store the record set for the select query?

Consider the following SQL (SQL Server 2008) statement: WITH MyResult AS ( SELECT Name, Row_ID AS ORD FROM Person Where Gender = @Gender ) SELECT * FROM MyResult WHERE ORD > 5 Is MyResult stored in a temporary table in the tempdb? Or does it do something else? We are optimising some queries and would lke to better unders...

Should I use .NET (System.Net.Mail) to batch send my web application's emails or SQL (msdb.sp_send_dbmail)?

Scenario: 1) My application is a .NET 3.5 C# web app and the database is SQL 2008. 2) Emails will be in the region of 100 to 1000 a day and are triggered by various web user interactions with the app. 3) Most emails will contain attachment(s) between 50KB and 5MB. Some emails will be HTML and some will be plain text. 4) All attachmen...

beginner's tutorial for report viewer?

Hello everyone, I am using VSTS 2008 + C# + .Net 3.5 + SQL Server 2008 + ASP.Net + IIS 7 to develop web application. Any quick and easy to learn tutorial for report viewer -- I want to generate report based on data from SQL Server 2008. Basic design and implementation function is fine, no need to learn advanced topics about report revie...

Is the code available that SQL Server uses to fill sys.sql_dependencies?

My current client is struggling with their release process. It's a bit complex and a little uncontrolled. I'm trying to fix the process problems, but in the meantime it would be helpful if I could put together a utility that could scan their scripts, look for dependencies, and generate the order in which those scripts need to run. Rathe...

SSIS package with trigger on the table

I have an SSIS package on Sql server 2008 which inserts data into a table in a transaction. There is a trigger on the table. That is causing the following exception while inserting - Bulk Insert with another outstanding result set should be run with XACT_ABORT on I am using OLEDB. How can I fix the error. ...

Subquery Caching with Sql Server 2008

I am creating a stored procedure with Sql Server 2008 which will return 2 result sets. The first query returns a result set that I would like to resuse as in the second query as a subquery (see example below). However, since the first query and the subquery essentially return the same data, I was wondering if there is some caching meacha...

named pipe problem using php to connect ot ms sql 2008

I'm am getting a named pipes error when I try to connect to ms sql server 2008 using a php script running an sqlsrv_connect command. In the ms sql configuration stuff tcp/ip, shared memory, and named pipes are all enabled. Everything is stored on the same server, the database, and the php script so I'm just using a "(local)" for the serv...

sql server error 40

Hi every body, I had made a database in sql server2008 on server,i create the login for tat & assign it some roles,i want to connect this database remotely,i had made the following steps on the server 1- enable TCP/IP 2- restart the sqlserver 3- add exception to windows firewall,sqlserver(process) & oso port 1433 but when i try to conne...