sql-server

Cross apply in Linq

Is it possible to use SQL Server 2008 CROSS APPLY with LINQ-2-SQL? Example SQL: select d.dateCol, tvf.descr, tvf.value from dateTable d cross apply tvFunction(d.dt, 'anotherParam') tvf where d.category='someCat' CROSS APPLY enables using values from a table (dateTable in the example) as parameters to a tablevalue function. This is v...

REPLACE and Unicode characters in SQL

I have some data with messed-up accented characters. For example in the data we have things like ClΘmentine that should should read Clémentine I'd like to clean it up with a script, but when I do this for example Select Replace('ClΘmentine', 'Θ', 'é') this is what I get: Clémenéine Apparently Θ matches both Θ and t. Any ideas ...

SQL Server 2005 - Restoring an encrypted DB on a different server

I have backed up an encrypted DB (symmetric key/certificate) and restored it on a different server. Unfortuantely we're having problems with the decryption... hoping someone can help. In the restored db, I can see the Symmetric Key and the Certificate in SSMS, but when I try to Open the key using the cert ( open symmetric key Key...

Why or How does FREETEXTTABLE give a rank value higher then others.

There is a store procedure that uses FREETEXTTABLE twice on two tables and then merges the results and returns the top 50. The problem is if I do a search on "Women of Brewster", the results returns "Confession of an ex doofus motha" with a rank of 143 from table A and second "Women of Brewster Place" with a rank of 102 from table B. ...

Effect of NOLOCK hint in SELECT statements

I guess the real question is: If I don't care about dirty reads, will adding the with (NOLOCK) hint to a SELECT statement affect the performance of: the current SELECT statement other transactions against the given table Example: Select * from aTable with (NOLOCK) ...

SQL Server 2005, need script to check for all constraints on table

I continue to get this error: Object '%s' cannot be renamed because the object participates in enforced dependencies I need to find a script that will help me to find all the dependencies that there is with this table. I will need to drop them, rename, then bring them back. Thanks. SQL Server 2005 ...

LINQ to SQL DataContext.Translate and properties with name different than the source.

I am working with some tables where I want the C# class to have a different property name than the underlying table column. However, when I use the Translate method to read the results, the properties that don't match the source name never get populated. Even when I use Linq to generate the SQL. For instance, my table is defined in the ...

How do I secure a SQL Server 2005 database?

I have a database for a web application that is home to some personal information about my users. What should I do to make sure the data is secure? Encrypting the data makes sense, of course... but what about stopping somebody from getting on the machine to begin with? What do I do about the developers that need access to the data, to...

How do I start extending MS SQL Reporting Services?

The reports I can churn out in SQL Server 2005 Reporting Services using the MS Business Intelligence Development Studio is rather limited for what I want to do. I have had a look at a similiar stackoverflow question and have had a browse through the MSDN website. I have managed to add some additional functionality from examples I've foun...

Parameter Sniffing (or Spoofing) in SQL Server

A while ago I had a query that I ran quite a lot for one of my users. It was still being evolved and tweaked but eventually it stablised and ran quite quickly, so we created a stored procedure from it. So far, so normal. The stored procedure, though, was dog slow. No material difference between the query and the proc, but the speed c...

Using virtual servers for hosting SQL Servers

We develop websites using SQL Server and ASP.NET. Development: web on developer PC, database on DEV server Testing: both on TEST server Live: both on LIVE server At the moment, DEV and TEST servers are separate physical servers. I'm considering making them virtual servers on the same physical servers. It is important that is easy...

Nullable GUID

In my database, in one of the table I have a GUID column with allow nulls. I have a method with a Guid? parameter that inserts a new data row in the table. However when I say myNewRow.myGuidColumn = myGuid I get the following error: "Cannot implicitly convert type 'System.Guid?' to 'System.Guid'." ...

Is there a .NET equalent to SQL Servers newsequentialid()

Hi We use Guid's for primary key, which you know is clustered by default. When inserting a new row into a table it is inserted at a random page in the table (because Guid's are random). This has a measurable performance impact because the DB will split data pages all the time (fragmentation). But the main reason I what a sequential Gui...

Set a SP return value to a variable in SQL Server

Hi, I have a sproc that returns a single line and column with a text, I need to set this text to a variable, something like: declare @bla varchar(100) select @bla = sp_Name 9999, 99989999, 'A', 'S', null but of course, this code doesn't work... thanks! ...

Are there any performance benefits of using SQL Server 2008 over SQL Server 2005?

Hi, Are there any performance benefits of using SQL Server 2008 over SQL Server 2005? ...

Query for the average call length for all users for a day

(sql server 2005) A person uses their cell phone multiple times per day, and the length of their calls vary. I am tracking the length of the calls in a table: Table: Calls [callID, memberID, startTime, duration] I need to a query to return the average call length for users PER DAY. Per day means, if a user used the phone 3 times, fi...

How to detect SqlServer connection leaks in a ASP.net applications ?

I'm currently doing some GUI testing on a ASP.net 2.0 application. The RDBMS is SQL Server 2005. The host is Win Server 2003 / IIS 6.0. I do not have the source code of the application because it was programmed by an external company who's not releasing the code. I've noticed that the application performs well when I restart IIS but a...

SQL Server xp_delete_file not deleting files

I'm trying to write some SQL that will delete files of type '.7z' that are older than 7 days. Here's what I've got that's not working: DECLARE @DateString CHAR(8) SET @DateString = CONVERT(CHAR(8), DATEADD(d, -7, GETDATE()), 1) EXECUTE master.dbo.xp_delete_file 0, N'e:\Database Backups',N'7z', @DateString, 1 I've ...

How do I disable query results when executing a stored procedure from a stored procedure?

Within a stored procedure, another stored procedure is being called within a cursor. For every call, the SQL Management Studio results window is showing a result. The cursor loops over 100 times and at that point the results window gives up with an error. Is there a way I can stop the stored procedure within the cursor from outputting an...

How do I generate a table of permissions granted to database tables for a database user?

Hi All, I have a SQL Server 2000 database with around a couple of hundred tables. There are several SQL user accounts that can access this database but each one has different permissions granted on tables in the DB. How do I create a script to give me a report of the permissions granted to a particular user. i.e. to generate something...