sql-server

I would like to combine ROLLUP with PIVOT - is that an option?

I have been using SELECT Author, ISNULL(MAX(CASE Status WHEN 'Duplicate' THEN NumDocs END),'') AS Duplicate, ISNULL(MAX(CASE Status WHEN 'Failure' THEN NumDocs END),'') AS Failure, ISNULL(MAX(CASE Status WHEN 'Rejected' THEN NumDocs END),'') AS Rejected, ISNULL(MAX(CASE Status WHEN 'Success' THEN NumDocs END),'') AS...

Select top 1 with UPDLOCK and READPAST sets exclusive lock on the entire table

I'm using the UPDLOCK and READPAST sql hints in a stored procedure in order to implement a sort of a table queue (I say a sort because I select top 1500 instead of a top 1, and I don't delete the rows after I select them. For more details, see question http://stackoverflow.com/questions/3636950/return-unlocked-rows-in-a-select-top-n-quer...

Transaction when writing to database and create an database

Hi we are building an multi tenancy solution where each tenant will have its own database. We will keep the information about the tenant in an index database. When creating an tenant the following steps will be made. Create Tenant class, save it to the database where it will get an incremental number which will be used to name the datab...

SQL Joins: Future of the SQL ANSI Standard (where vs join)?

We are developing ETL jobs and our consultant have been using "old style" SQL when joining tables select a.attr1, b.attr1 from table1 a, table2 b where a.attr2 = b.attr2 instead of using inner join clausule select a.attr1, b.attr1 from table1 as a inner join table2 as b on a.attr2 = b.attr2 My question is that in the long run, i...

PHP MS SQL Unix Driver - Microsoft or FreeTDS

I am running a LAMP server but now need to connect to MS SQL (client request). I have heard Microsoft has a driver, but can't verify if Does anyone know if the Microsoft driver is available for Unix? If not, should I just stick with FreeTDS? This appears to be recommended by PHP, however install documentation seems lacking. Any directi...

Can I change server authentication to mixed mode in sharepoint 2010?

I want to know weather I can used mixed mode authentication on sql server instance being used for SharePoint2010 installation; without breaking the licence terms for SP2010. ...

Strange issue in SQL Management Studio IDE with CR instead of CRLF

I've encountered a strange feature (that may be related to SQL Management Studio) with regard to the placement of return characters at the end of SQL Statements. Whilst the query runs just fine within the ID, the feature in question was breaking our deployment scripts. Essentially, for some reason, certain lines were being terminated by...

How Can I Find All Columns That Contain A String and Null Those Values

My goal is to write a SQL Server script (2008 R2 if it matters) that nulls out all values in all tables where the column name contains "Qualifiers". E.g. Table A contains columns named "TemperatureQualifiers" and "SalinityQualifiers". For all rows in that table, those values should be set to null. There are also several other tables tha...

How to improve performance when deleting entities from database?

I started an ASP.NET project with Entity Framework 4 for my DAL, using SQL Server 2008. In my database, I have a table Users that should have many rows (5.000.000 for example). Initially I had my Users table designed like this: Id uniqueidentifier Name nvarchar(128) Password nvarchar(128) Email nvarchar(128) Role_Id int...

Combine CTE "WITH" and a "WITH XMLNAMESPACES...." in SQL Server

Has anyone managed to create a CTE in SQL Server's T-SQL that also includes a WITH XMLNAMESPACES declaration? It seems both WITH keywords insist on being the "first in the T-SQL batch", and that doesn't really work.... I tried: WITH XMLNAMESPACES('http://schemas.myself.com/SomeSchema' as ns) WITH CTEQuery AS ( SELECT (list of fields) ...

SSMS: Way to use modal dialogs rather than tabs?

Is there a way in SQL Server Management Studio to use modal dialogs to view or edit a View, Stored Procedure or User Defined Function? As it is now anytime you want to see/modify their declaration, it has to be scripted as ALTER VIEW ALTER PROCEDURE ALTER FUNCTION and it is placed on a new dummy tab. i prefer the old fashioned OK C...

How many connections are available in the ADO.NET connection pool

Is it possible (from a asp.net application) to check how many connections of the ADO.NET connection pool are currently in-use and how many are available (not currently in-use)? ...

SQL Server: ORDER BY in subquery with UNION

i have two queries being combined with a UNION ALL1: --Query 1 SELECT Flavor, Color FROM Friends   --Query 2 SELECT Flavor, (SELECT TOP 1 Color FROM Rainbows WHERE Rainbows.StrangerID = Strangers.StrangerID ORDER BY Wavelength DESC ) AS Color FROM Strangers Both of which, of course, work fine separately, but ...

In SQL Server 2005, is it possible to set transaction isolation level on a per-user basis?

In SQL Server 2005, is it possible to automatically set transaction isolation level to, say, read uncommitted an a per-user basis? (So for instance, if I set such a login option for user Fred, Fred wouldn't have to remember sprinkle his select statements with NOLOCK hints or remember to add in a set transaction isolation level statement...

Sending files from android to the MS SQL Server 2008

Hello I want to send files (.csv) from android to the MS SQL Server 2008 . Shoud I use HTTPClient ? How can I do that? ...

sql server 2005 connecting thru windows authentication

How would I be able to connect to MS SQL Server 2005 through Windows authentication from JAVA. Is it possible? Thanks ...

how to find date difference when dates are places in different rows in same table?

I have a table:: ItemID VersionNo CreatedDate ------------------------------- 1 3 7/9/2010 1 2 7/3/2010 1 1 5/3/2010 1 0 3/3/2010 2 0 4/4/2010 3 1 4/5/2010 3 0 3/4/2010 ...where Version 0 means .. its a newly produced item. Here ...

t-sql unique constraints over 7 columns by sql management studio

i want to create unique constraints in table for 7 columns, so when someone want insert data in this table this colums together are unique. In oracle this is very simple, but here .... I can do this by sql code: CREATE TABLE Example (Col1 int NOT NULL, Col2 int NOT NULL, CONSTRAINT CK_Col1_Col2 UNIQUE NONCLUSTERED (Col1, Col2) ) Anyo...

Is there any way to use SqlTypes with a SqlDataAdapter?

I'm trying to write some simple C# code that will select some data from a SQL Server instance, modify the data, and update the changes back to the database. But I'm having a hard time figuring out exactly how to do this. Here is a simplified version of my code: using (SqlConnection conn = new SqlConnection("Server=(local);Integrated S...

Total size of an index or primary key can not exceed 900 bytes

When I try to create UK for 7 columns I get Total size of an index or primary key can not exceed 900 bytes. How can I solve this error? ...