sql-server

SQL: SELECT n% with pictures, (100-n)% without pictures

Hi all, we have a DB which stores users who may have pictures. I am looking for an elegant way in SQL to get the following results: Select n users. Of those n users e.g. 60% should have an associated picture and 40% should not have a picture. If there are less than 60% users having a picture the result should be filled up with users wi...

Problems with MSDTC - remote transactions

Hi! We're in the process of moving our SQL Server to it's own machine, but I'm having issues getting transactions through MSDTC to work. Here is the error message ASP.Net is generating for me: The transaction manager has disabled its support for remote/network transactions I have tried googling around for this, but haven't m...

Huge Errorlog with SQL Server 2005 Express (15GB)

With SQL Server 2005 Express (obeserved on XP and Server 2003), I get sometimes huge Error logs files in production: The file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG grows to fill the disk (file size becomes more than 15 GB). This file is not the transaction log, just the error log : a text log for SQL Server. ...

How to use ROWLOCK with EJB

I have a problem where I get a deadlock on a MS SQL Server. The same code runs without problems on MySQL. My problem is that I receive a request to delete a job (which is attached to a device), and afterwards I receive a request to create a new job for the same device. Most times this works without any problems, but once in a while the ...

Permission Denied Error - SQL 2000

While executing multple update statements on a particular table simultaneosly, I am getting an error - Permission Denied. Previously, the same was working perfectly. What could be the reason this is getting failed now? ...

Where can I find friendly strings for SQL Server versions?

The friendly string for 9.00.4035.00 is SQL Server 2005 SP3 Express Edition. I would like to convert version numbers to string by accessing only registry or a dictionary. Can I find a list? ...

Database size is huge

I have the following problem. We have a database that stores binaries in the database. We know the size of the database can be big so we removed all the binaries from the database and used the task "shrink" on it. This way we hoped that the database would be much smaller. These are the results: before removal size was: 20 gigabyte after...

SQL nested query

hello I have a table with the attributes PARAMETER_ID, Value and Time and I want to have each PARAMETER_ID with its min(Value) and the Time when the Value is minimum and its max(Value) and the Time when the Value is maximum, could you please tell me the query? thanks alot ...

asp.net + MS SQL Server: Best Source Control

I work on a growing web team that needs to adopt a Source Control system. We looked into Source Safe, but were put off by it's lack of SQL Server source control. The Visual Studio Team System range looks like it does the trick, in terms of source code + database - but I must admit to be confused by the various versions. So my questions...

How to Execute T-SQL from c#?

Can anybody give an example for executing a T-SQL statement using C#? ...

LINQ to SQL and the DBML file - multiple database development

Hello. The way I develop may not be correct, any advice welcome. At the moment I have a WPF application that uses a SQL2008 database. I have a copy of the database on a laptop and on my home machine. My application is versioned using SVN and I am obviously able go from the work laptop to the home machine and update/commit as required to...

Sorting SQL table

Hi, can anyone help me with T-SQL to sort this table ID Comment ParentId -- ------- -------- 3 t1 NULL 4 t2 NULL 5 t1_1 3 6 t2_1 4 7 t1_1_1 5 to look like this ID Comment ParentId -- ------- -------- 3 t1 NULL 5 t1_1 3 7 t1_1_1 5 4 t2 NULL 6 t2_1 4 Kind regar...

SQL Server 2005 SP Deadlock issue

I have a scheduled job with a SP running on daily basis (SQL Server 2005). Recently I frequently encounter deadlock problem for this SP. Here is the error message: Message Executed as user: dbo. Transaction (Process ID 56) was deadlocked on thread | communication buffer resources with another process and has been chosen as the deadlock...

How to execute a stored procedure from c# program

Hi i want to execute this StoredProcedure from c# program How can i do this using c# Any Help is Greatly Apreciated I have written the following stored procedure in sqlserver query window and saved it as stored1 use master go create procedure dbo.test as DECLARE @command as varchar(1000), @i int SET @i = 0 WHILE @i < 5 BEG...

Nonsense Error in SQL Server Management Studio

I have this query that spawns the following error: SELECT * FROM Quota WHERE LEFT(QtLabel, LEN(QtLabel)-2) IN ( '1032', '3300', '9682' ) Msg 536, Level 16, State 5, Line 1 Invalid length parameter passed to the SUBSTRING function. Am I doing something wrong? It tends to show up when I use the LEN() function. Might it be a datat...

SQL Server: How to create a temp table with unkown columns dataype/names?

I need to make a query on multiple databases. I got the part for building the query for every database but now i need to put the result in something for each query then i can return it. @requete is a query ALTER PROCEDURE [dbo].[RequeteMultiBd] @requete varchar(max) AS BEGIN --get server + database name select dbo.trim(Ser...

LINQ Inserts without IDENTITY column

Hello I'm using LINQ, but my database tables do not have an IDENTITY column (although they are using a surrogate Primary Key ID column) Can this work? To get the identity values for a table, there is a stored procedure called GetIDValueForOrangeTable(), which looks at a SystemValues table and increments the ID therein. Is there any ...

SQL Error: The multi-part identifier "tableName.ColumnName" could not be bound.

When LEFT JOINing tables in a SQL query, sometimes I need to reference multiple tables in the ON clause. For example: SELECT p.Name, j.Job, s.Salary FROM PeopleTable p, JobTable j LEFT JOIN SalaryTable s ON s.PeopleID=p.PeopleID AND s.JobID=j.JobID However, the above would give this error: SQL Error: The multi-part identifier "p.Peop...

SQL Server: Why do these queries return different result sets ???

Query 1 = select top 5 i.item_id from ITEMS i Query 2 = select top 5 i.item_id, i.category_id from ITEMS i Even if I remove the top 5 clause they still return different rows. if I run "select top 5 i.* from ITEMS i" this returns a completely different result set !! ...

Performance of OPENROWSET to copy data from one server to another server

Can we write a query like INSER TNTO Customers SELECT * FROM OPENROWSET( 'SQLNCLI', Remote Server Settings , 'SELECT * FROM Customers) Remote Server is on some other server over internet public IP. Will this be faster compared to SqlBulkCopy? I need to create a slave database which can regularly copy data from server accessible thr...