sql-server

SQL Query to find duplicates not returning any results

I know there are duplicate account numbers in this table, but this query returns no results. SELECT [CARD NUMBER],[CUSTOMER NAME],[ACCT NBR 1],[ACCT NBR 2], COUNT([ACCT NBR 1]) AS NumOccurences FROM DebitCardData.dbo.['ATM Checking Accts - Active$'] GROUP BY [CARD NUMBER],[CUSTOMER NAME],[ACCT NBR 1],[ACCT NBR 2] ...

Detail Dimension for Drillthrough

I have created a number of type 1 dimensions to hold customer/subscription level details. These dimensions are very large compared to any other dimensions I am using with nearly a 1 to 1 relationship to facts. The dimensions are only being used to provide drillthrough details. It's all working but the size of these dimensions is quite...

Best way to randomly select rows *per* column in SQL Server

A search of SO yields many results describing how to select random rows of data from a database table. My requirement is a bit different, though, in that I'd like to select individual columns from across random rows in the most efficient/random/interesting way possible. To better illustrate: I have a large Customers table, and from th...

What is the difference between "db_owner" and "the user that owns the database" in SQL Server 2000?

I'm trying to better understand why one of our database update scripts failed to work properly at a particular customer site, and narrowed it down (I think) to database ownership and roles. Disclaimer: I'm actually waiting to hear back from the customer's DBA so they can tell us if they upgraded their SQL database recently and so we...

LINQ to Entities, SQL Server version and setting ProviderManifestToken at runtime

We have developers some developers who are developing against a SQL Server 2005 database, while others are using 2008. We just discovered that generating the edmx against a 2008 database set the ProviderManifestToken to 2008, which means some queries won't work against a 2005 database. While this is a known issue, is there any way to...

How to formulate a SQL Server indexed view that aggregates distinct values?

I have a schema that includes tables like the following (pseudo schema): TABLE ItemCollection { ItemCollectionId ...etc... } TABLE Item { ItemId, ItemCollectionId, ContributorId } I need to aggregate the number of distinct contributors per ItemCollectionId. This is possible with a query like: SELECT ItemCollectionI...

Batch vs SQL statement

a) A SQL statement is a single SQL command (for example, SELECT * FROM table1 or SET NOCOUNT ON). A batch on the other hand, is a number of SQL statements sent to the server for execution as a whole unit. The statements in the batch are compiled into a single execution plan. Batches are separated by the GO command So the only diffe...

Two different definitions of database schema

a) I found two definitions of schema: FIRST - A set of information that describes a table is known as a schema, and schemas are used to describe specific tables within a database, as well as entire databases (and the relationship between tables in them, if any). SECOND - A database schema is a way to logically group objects ...

List of all tables with a relationship to a given table or view

In SQL Server is there a command to return a list of all tables with a relationship to a given table or view? EDIT: SQL SERVER 2008 ...

How do I switch to a SQL Server Server Database that will exist after another command?

I can't get this script to run, because SQL management studio 2008 says the table "NewName" does not exist. However, the script's purpose is to rename an existing database, so that it does exist when it gets to that line. Ideas? Use Master; ALTER DATABASE OldName SET SINGLE_USER WITH NO_WAIT; ALTER DATABASE OldName MODIFY NAME = NewNam...

Why isn't the Cache invalidated after table update using the SqlCacheDependency?

I have been trying to get SqlCacheDependency working. I think I have everything set up correctly, but when I update the table, the item in the Cache isn't invalidated. Can you look at my code and see if I am missing anything? I enabled the Service Broker for the Sandbox database. I have placed the following code in the Global.asax fil...

SQL Server, View using multiple select statements

I've banging my head for hours, it seems simple enough, but here goes: I'd like to create a view using multiple select statements that outputs a Single record-set Example: CREATE VIEW dbo.TestDB AS SELECT X AS 'First' FROM The_Table WHERE The_Value = 'y' SELECT X AS 'Second' FROM The_Table WHERE The_Value =...

Visual Studio 2010 Reporting Services Projects?

So, it seems that VS 2010 does not support SRSS projects. At least not old ones....Does anyone know what the status on this situation is and whether one can author new SRSS reports using VS2010 or if one should just use VS2008 BIDS? ...

SQL Server 2005 Sleeping SPID blocking another SPID...

I find many sleeping process my SQL Server database and looks like one of those sleeping SPIDs is blocking another process, and that process is getting suspended too... Could some one please explain this... 1.) How can a sleeping process block another process? 2.) I see many sleeping process...is this normal? Thanks ...

Should I use "User Defined Functions" in SQL server, or C#?

I have a fairly complicated mathematical function that I've been advised should be implemented as a User Defined Function in SQL Server so that it can be used efficiently from within a SQL query. The problem is that it must be very efficient as it may be executed thousands of times per second, and I subsequently heard that UDFs are ve...

Table rows with identifying parameter in each row SQL SERVER 2008 into single row

Sorry - my question title is probably as inept at my attempt to do this. I have the following (well, similar) in a table in a CMS pageID key value 201 title Page 201's title 201 description This is 201 201 author Dave 301 title Page 301's title 301 descriptio...

Auto-complete editor for SQL statement

Is there any plugings or text editor to auto-complete SQL statement? I am using SQL Server Management Studio (ssms) 90% of time, but most of time I have to type SELECT FROM WITH(NOLOCK) WHERE blahblah. Trying to find a more efficient way. Thanks. ...

how to convert the datetime value to hour

I have datetime value as 2010-04-07 09:00:00.000 2010-04-07 14:30:00.000 how to convert the 14:30 to 2:30 pm ...

Simple select not working on JDBC SQL Server?

I am trying to move project which was using MySQL database to the one that uses SQL Server 2008, But the select that was working in mysql is no longer working in SQL Server PreparedStatement statement = connection .prepareStatement("select u.user_firstname,u.user_lastname from user_details u, login l where l.username...

Loading Fact Table + Lookup / UnionAll for SK lookups.

I got to populate FactTable with 12 lookups to dimension table to get SK's, of which 6 are to different Dim Tables and rest 6 are lookup to same DimTable (type II) doing lookup to same natural key. Ex: PrimeObjectID => lookup to DimObject.ObjectID => get ObjectSK and got other columns which does same OtherObjectID1 => lookup to DimOb...