sql-server

When to use EXCEPT as opposed to NOT EXISTS in Transact SQL?

Hi, I just recently learned of the existence of the new "EXCEPT" clause in SQL Server (a bit late, I know...) thru reading code written by a coworker. It truly amazed me! But then I have some questions regarding its usage: when is it recommended to be employed? Is there a difference, performance-wise, between using it versus a correlate...

Out of a sample of 100 demands what else was asked for?

I am doing some work on an inbound call demand capture system where each call could have one or more than one demands linked to it. There is a CaptureHeader table with CallDate, CallReference and CaptureID and a CaptureDemand table with CaptureID and DemandID. EDIT: I have added some representative data to show what would be expected i...

Best SQL Server isolation level for web application?

We have a website using ASP.NET MVC and SQL Server 2008 and we are using the default transactionscope isolation level which is Serializable. But it makes the application unusable if any transaction is opened as we have a table that being used by almost everything and it runs like select * from table1 where id = 1 So I think it locks ...

Lock out non-dbo

Is there an easy way to lock a sql server express 2005 so that only DBOs can get to it, assuming you have a system where everyone has been granted rights individually and you can't just disable a role? ...

SQL Server XML (multi-namespace) Parsing question

I'm trying to use SQL Server Integration Services (SSIS) to parse an XML file and map the elements to database columns across several tables in a single database. However, when I use the Data Flow Task->XML Source to try and parse an example XML file (that file is located here, XSD is located here), it says "http://www.exchangenetwork...

Denormalizing Data (Maybe A Pivot?)

I have a simple table containing Student Numbers and corresponding Teacher Numbers, and I need to denormalize it for input to a legacy system. For example, here's what the data looks like now: StudNumber TeacherNumber 445 57315 445 88584 445 95842 858 88115 858 65443 858 57315 858 211...

SQL Server Where Clause Case Statement?

I have a Where Clause that checks the existence of rows in a subquery, but I only want to execute that check if a bit is set to 1. So for example: Select * from Listing l Where l.IsDeleted=1 AND CASE WHEN @MustHasPicture = 1 THEN ( EXISTS ( SELECT NULL AS [EMPTY] FROM [dbo].[ListingPictures] AS [lp] INNER JOIN...

sql server 2005 developer edition

I installed sql server 2005 developer edition on my pc. I am not able to see server in management studio. I installed default instace as an installation option. ...

Two SUM queries together

I have a table "Events" and a table “Slots” where Slots.SlotID = Events.MainSlot OR Events.ExtraSlot. I need to sum the number of “Attendees” per time slot (as MainSlot and as ExtraSlot - ExtraSlot is optional) Table "Events" ID------Name----------MainSlot-------ExtraSlot-------Attendees 1-------Event1--------1 -------------n/a-----...

What is the fastest method for importing from the active sheet in Excel to SQL Server?

What is the fastest way to import data into a SQL Server database directly from the active worksheet in Excel? I have had great success simply looping through the rows and columns, generating a SQL string, opening an ADODB.Connection and executing the SQL. That solution, however, is too slow for large datasets. So I am testing the Jet ...

Replace Default Null Values Returned From Left Outer Join

I have a Microsoft SQL Server 2008 query that returns data from three tables using a left outer join. Many times, there is no data in the second and third tables and so I get a null which I think is the default for left outer join. Is there a way to replace the default values in the select statement? I have a workaround in that I can ...

TSQL Join efficiency

I'm developing an ASP.NET/C#/SQL application. I've created a query for a specific grid-view that involves a lot of joins to get the data needed. On the hosted server, the query has randomly started taking up to 20 seconds to process. I'm sure it's partly an overloaded host-server (because sometimes the query takes <1s), but I don't th...

tsql to find status of a database in words

I want to know status of every database across a SQL Server farm. I was using: select name, case status when 32 then 'loading' when 128 then 'recovering' when 512 then 'offline' when 4096 then 'single user' when 64 then 'pre recovery' when 256 then 'not recovered' el...

SQL Command to execute multiple times?

I have situations that I need to write multiple rows of the same value to setup some tables. Say I have to add 120 rows with two columns populated. I am looking for a shortcut, instead of having the Insert line repeated n times. How to do this? ...

SQL Date function question

I'm using SQL Server 2005 and I have a DateTime column. How can I multiply the hour and minute of a DateTime column by 1.2 and return the new value So something like: SELECT MyColMinute = DATEPART(minute, myCol) * 1.2 MyColHour = DATEPART(second, myCol) * 1.2, MyCol From NyTable Of course the above won't work! So for example myCo...

How to generate a date for the given time?

Using VB.NET and SQL Server 2005 I want to generate a date according to the given Outtime, Am entering the value like ID Date Intime Outtime Holiday 001 23-02-2009 08:00:00 17:00:00 no 001 24-02-2009 17:00:00 08:00:00 no 001 25-02-2009 10:00:00 16:00:00 no 001 26-02-2009 18:00:00 20:00:00 no 001 27-02-2009 yes Ex...

How to repeat the values between the two dates?

Using SQL Server 2005 I want to generate the table values between the two dates Table1 ID Date Intime Outtime 01 12-02-2009 10:00:00 17:00:00 02 13-02-2009 08:00:00 16:00:00 03 14-02-2009 09:00:00 21:00:00 04 15-02-2009 Suppose I want to generate the above table values between the two dates. For Example, Given Date: start date - ...

Database physical files storage locations

Im setting up a SQL 2008 Cluster of 3 active ndoes. I have 2 partitions on the SAN available for each node. I just wanted to know the ideal configuration of how i should use these partitions for each node, as in what .mdf and .ldf file should be where ? ...

identity from sql insert via jdbctemplate

Is it possible to get the @@identity from the SQL insert on a Spring jdbc template call? If so, how? TIA ...

Creating a job in SQL Server 2005

Hi, Am pretty new to SQL Server 2005. Can someone help me to create a job in SQL Server? This link(http://www.databasedesign-resource.com/sql-server-jobs.html) says to create under the jobs category in managememt tab. But i am not able to find one such category in my SQL Server Management Studio. Is it not possible to create a job using...