sql-server-2005

Unable to create index because of duplicate that doesn't exist?

I'm getting an error running the following Transact-SQL command: CREATE UNIQUE NONCLUSTERED INDEX IX_TopicShortName ON DimMeasureTopic(TopicShortName) The error is: Msg 1505, Level 16, State 1, Line 1 The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.DimMeasureTopic' an...

SQL Server Group By which counts occurrences of a score

Hi, This might be a bit difficult to explain but I have two columns in my SQL server database which I have simplified... Items ID itemName voteCount score Votes itemID score So, basically I am storing every vote that is placed in one table, but also a count of the number of votes for each item in the item table along with it's averag...

Why doesn't this select statement, setting a variable, work?

I am writing a stored procedure like this.. declare @avg float set @avg = select avg(rating) from videorating where videoid = 4 Can I write it like this? Can I store the value in @avg? ...

SQL installer in .net SetUp project

I have an winform application which uses SQL 2005 as database.Client wants single installer where all the setups should install including SQL 2005. How do i implement SQLEXPR32.exe in my setup project so when application is installed SQL server 2005 also install. Can i make this SQLEXPR32.exe as custom actions ? I know this question is a...

How to use sql server 2005 stored procedures in asp.net mvc?

I have just started a new web application with asp.net mvc and sql server 2005... Thus far in my webform applications i used ADO.NET... I want the same in my asp.net MVC apllication... I have a database in sql server 2005 with all the stored procedures... Now i want to use those stored procedures in my MVC application... I dont use any...

Windowed Functions in SQL Server

I have a table called Orders in which the data looks like this: EMpID OrderValue OrderID 1 100 1 2 167 89 .... There are multiple orders for each empID. What I want is to get output in this form EMPID RANK VALUETOTAL VALUETHISEMPID 1 1 300 100 4 2 300 50\ ..... If there are mu...

Merge data for same id

ItemCode AttributeCode AttributeValue ----------- -------------------- ---------------- ITEM-000001 BUTTONS 2B ITEM-000001 COLOR NAVY ITEM-000001 FABRIC A-W ITEM-000001 LAPEL NOTCH ITEM-000001 PATTERN STRIPE ITEM-000001 SEASON A6 ITEM-000001 SU...

SSIS OlEDB Connection manager Error

When am using sequence container to roll back my transactions in execute sql task i am getting the error Connection manager Error: The SSIS Runtime has failed to enlist the OLE DB connection in a distributed transaction with error 0x8004D025 "The partner transaction manager has disabled its support for remote/network transactions.". hav...

Adding linked server - SQL Server 2005 - Changing the name later

Hello, I'm developing a web app in a testing environment with test sql servers and databases. I'm currently adding a linked server and accessing the databases and tables in the linked server using [Servername].[DatabaseName].dbo.[TableName]. But after pushing it to production the DB servers name will change. So should i need to open ea...

Sorting Dynamic column headings in SSRS

Trying to get my report to sort on column headings in a report. Can make it happen normally, but, the difference here is it is coming from a Stored procedure and the columns can be different each time. They are dates and the report shows 6 periods - and always just the 6 periods - but period 1 might be a week this time and a month the ...

statement "USE @dbname" doesn't work, why? How to do that?

I've got this t-sql snippet: DECLARE @db_name varchar(255); SET @db_name = 'MY_DATABASE'; -- assuming there is database called 'my_database' USE @db_name -- this line ends with error "Incorrect syntax near '@db'." But USE with variable (third line of snippet) doesn't work. Why it doesn't work? ...

Filtering SQL Rows

Table Schema ID Activate_Date InActivate_Date 1 2009-12-18 10:25:19.470 2010-01-13 08:32:30.130 2 2009-12-18 10:25:19.470 2010-01-13 08:32:30.253 3 2009-12-18 10:25:19.470 2010-01-13 08:32:30.363 4 2009-12-18 10:25:19.470 2010-01-13 08:32:30.583 5 2009-12-18 10:25:19.470 2010-01-13 08:32:...

How safe are SQL Server 2005 MDF files? (re: security)

We've started using SQL Server 2005 Express for a project and I noticed that every database has it's own MDF/LDF files. Whenever we need to duplicate our database (to another SQL Server) we simply copy these files and then attach them to the database. However, this has me wondering about the security of these files. If somebody from t...

creating funtion using newID()

I keep getting this error: Any Ideas? Invalid use of side-effecting or time-dependent operator in 'newid' within a function. I am working with Ms-sql 2005 Create Function [dbo].[GetNewNumber]( ) RETURNS int AS BEGIN Declare @code int set @code = (SELECT CAST(CAST(newid() AS binary(3)) AS int) ) RETURN (@code) END ...

TSQL: Datetime overlapping and interval values

Need help to create a query for this. Start | End 2009-01-01 06:00:00 | 2009-01-01 14:00:00 2009-01-01 06:00:00 | 2009-01-02 06:00:00 2009-01-02 07:00:00 | 2009-01-02 08:00:00 2009-01-03 06:00:00 | 2009-01-03 14:00:00 2009-01-03 09:00:00 | 2009-01-03 11:00:00 2009-01-04 22:00:00 | 2009-01-05 06:00:00 2009-01-05 01:00:00 | ...

Using a Right Outer Join to Match Records from Two Different Databases

SQL 2005: I am trying to create an outer join that will pull records from two different databases. My objective is to determine which records in database B don't have matching records in database A. When I tried running the query, it returned the error below. I am not sure how to get around this error: 'Tables or functions 'Asset...

Write a T-SQL query that filters records containing NCHAR(2028)

My ultimate goal is to write a sql script that selects data from a particular table where a nvarchar(max) column contains the character NCHAR(2028). But the obvious: select * from tablename where columnname like '%' + NCHAR(2028) + '%' returns all rows. ...

Sql Server Compact 2005 on Visual Studio 2008

I'm working on a Windows Forms application that interacts with a Sql Compact database file created by SQL Server 2005. This application was originally developed in Visual Studio 2005 but was recently converted to a Visual Studio 2008 solution. In regards to Sql Compact, we made sure the references were all still set to the assemblies t...

CROSS APPLY Performance question

Is it possible to improve performance by taking the following SQL: SELECT t1.ID, t1.NAME, t2.SubName, t2.RefValue FROM Table1 as t1 CROSS APPLY ( SELECT Top 1 t2.SubId, t2.SubName, t3.RefValue FROM table2 as t2 INNER JOIN table3 as t3 ON t2.SubId = t3.SubId ORDER BY LastUpdated desc ) as...

SQL Query, SELECT Top 2 by Foreign Key Order By Date

I need a SQL query that returns the top 2 Plans by PlanDate per ClientID. This is all on one table where PlanID is the PrimaryID, ClientID is a foreignID. This is what I have so far --> SELECT * FROM [dbo].[tblPlan] WHERE [PlanID] IN (SELECT TOP (2) PlanID FROM [dbo].[tblPlan] ORDER BY [PlanDate] DESC) This, obviously, only retu...