sql-server-2008

Finding top n for each unique row

I'm trying to get the top N records for each unique row of data in a table (I'm grouping on columns b,c and d, column a is the unique identifier and column e is the score of which i want the top 1 in this case). a b c d e 2 38 NULL NULL 141 1 38 NULL NULL 10 1 38 1 NULL 10 2 38 1 NULL 1 1 38 1 ...

SQL update to record with nearest data

In SQL server 2008: Suppose I have two tables. Table1 has 3 fields: Name, Date1 and Date2. Currently, all the Date2 entries are NULL. (Name, Date1) form a unique key. Table2 has 2 fields: Name and Date2. (Name, Date2) form a unique key. Every "Name" in Table1 has at least one corresponding entry in Table2. Now, I want to update all...

Licensing a SQL Server 2008 for a web site

I would like to user SQL Server 2008 for my public web site. It will be installed on a quad-core CPU and it will be used only through several web applications installed on the same server. My options are: Per-CPU license - around 5-6k US$ Per client - around 1k US$ + cost per client Now, I don't understand the second model. I have ...

Which right grants user a right to grant another right to himself in SQL 2008?

I need to grant a db_datawriter before executing SqlBulkCopy and remove it after: try { "EXEC [db_mod].[sys].[sp_addrolemember] N'db_datawriter', N'my_user'" // via SqlCommand bulk.WriteToServer(table); } finally { "EXEC [db_mod].[sys].[sp_droprolemember] N'db_datawriter', N'my_user'" // via another SqlCommand } but I'm getti...

two datasets - sql reporting services 2008

Hello, please can someone help. I have two datasets I'm working with and two tables. I've managed to do one expression correct so do not understand why my second won't work. My first expression is where I need to state the target number based on a result e.g. =IIF(Fields!Line.Value = "B1", "10", IIF(Fields!Line.Value = "C1", "15", ""...

FILESTREAM files being left behind after row deleted

I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed that even when I have deleted rows containing FILESTREAM data, the physical data file doesn't seem to get deleted. By the physical file, I mean the file in SQLServer's managed directory with a uniqueidentifer as the filename not the original file added to ...

SQL Server - OPENQUERY

I am using an Openquey which has been working fine on SQL Server 2005, I have 1 server that is SQL Server 2008 which this does not work on. If I run the following: SELECT * FROM OPENQUERY([Manchester], '[Manchester].[PilotWebApp].[DBO].rsp_HandheldPerformance ''10/01/2009'', ''10/10/2009''') I get this error: Cannot ...

Configuring a SQL Server (2008) Monitor Server

After having a period of logshipping failures going unnoticed (due to a stopped SQL Agent on the secondary server) I'm looking at configuring some monitoring. Having seen the ability to specify a "Monitor Server instance" on the SQL Server 2008 log shipping setup and the relavant MSDN docs (http://msdn.microsoft.com/en-us/library/bb5107...

Could not load file or assembly 'Microsoft.SqlServer.Types

I have web application which we deployed in a production . We have separate servers for WEB and Database. The DB is SQL Server 2008 and it is hosted on a completely different server and we have our IIS installed on a different server. On my web server, we get following error. Could not load file or assembly 'Microsoft.SqlServer.Types, V...

Windows CE - Database

I need to setup an application to scan a barcode from a packing slip and the associated fulfillment items on a windows CE 5.0 device and update the inventory on the server. I'm using VB.NET. However, what is the best way to interact with the database? Integration Services, ADO.NET, RDA... etc... it's a bit overwhelming trying to figur...

Allow special characters SQL Server 2008

I am using SQL Server 2008 express edition and its collation settings are set to default.I wish to store special characeters like á ,â ,ã ,å ,ā ,ă ,ą ,ǻ in my database but it converts them into normal characters like 'a'. How can I stop SQL Server from doing so? ...

How do I convert a nested select to joins when nested select has a temp table?

I have the following SQL. Tables defined. #tbContinent -------- ContinentID | ContinentName AddressInCountry -------- AddressID | CountryID AddressInContinent -------- AddressID | ContinentID NameInAddress -------- AddressID | NameID I then have the following SQL: --- Insert into tbName DECLARE @tbName TABLE ([ID] int, [Add...

how do I remove nested select statement

Hi. I have a Name table with the columns NameID Name TypeID With the following SQL SELECT[NameID] FROM[Name] WHERE[TypeID] = @TypeID AND NameID >= (SELECT MIN([NameID]) FROM [Name] WHERE [Name]='Billy' AND [TypeID]=@TypeID) Ive been asked to convert this to an Inner Join without using any nested select but n...

Group Similar records Sql Server 2008

Hi All, I will be writing a query to achieve something like below, please help me TableName: Application AppId (PK,int) AppType (bit) 1 0 2 0 3 0 4 0 5 1 6 0 7 0 8 0 9 1 10 1 11 0 12...

Cast collation of nvarchar variables in t-sql

I need to change the collation of an nvarchar variable. By documentation: (...) 3. The COLLATE clause can be specified at several levels. These include the following: Casting the collation of an expression. You can use the COLLATE clause to apply a character expression to a certain collation. Character literals a...

Get XML schema from database schema (SQL Server 2008 diagram)

Get XML schema from database schema (SQL Server 2008 diagram) I am using SQL Server 2008. Is their is a way to do this in the SQL studio enterprise manager? Rather than write code or use an external tool ...

Visual Studio 2008 adding SQL Server database (SQL Server 2008 Management Studio) not working

I'm trying to practice using the ASP.NET MVC at home, but I ran into an impossible problem. I cannot open a connection to SQL Server 2008, I get this error: "Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly. ..." I've googled around for numerous responses, none of them either working or addres...

What's the best place for a database-backed, memory-resident global cache in an ASP.NET web server?

I have to cache an object hierarchy in-memory for performance reasons, which reflects a simple database table with columns (ObjectID, ParentObjectID, Timestamp) and view CurrentObjectHierarchy. I query the CurrentObjectHierarchy and use a hash table to cache the current parents of each object for quickly looking up the parent object ID,...

Converting an integer to a 0-padded string

In SQL Server 2008, I want to represent an integer as a 3-character string - so: 3 becomes '003' 5 becomes '005' 107 becomes '107' How can I do this? ...

How do I get around a 'circular reference' in an Inner join

Hi, I have the following 'circular dependency' in my Inner Join, any ideas how to get round it? SELECT *FROM Reference INNER JOIN ReferenceInActivity ON Activity.ActivityID = ReferenceInActivity.ActivityID INNER JOIN @tbActivity AS Activity ON ReferenceInActivity.ReferenceID = Reference.ReferenceID I get the error: Msg 4104, Level 1...