sql-server-2008-r2

How to concatenate strings from multiple rows in one column + inner join in one query

一曲冷凌霜 提交于 2019-12-30 04:38:07
问题 I have a query with the following result: query: SELECT Tasks.TaskId, Comments.Comment, comments.timespent FROM comments INNER JOIN tasks ON comments.entityid = tasks.taskid WHERE ( comments.entity = 1 ) GROUP BY Tasks.TaskId, Comments.Comment, comments.timespent Result: TaskID Comment TimeSpent __________________________ 111754 C1 4 111754 C2 1 111754 C3 79 Please tell me how should I write my query to get the result as follows: TaskID Comment TimeSpent __________________________________

How to implement Socket.IO with ASP.Net, IISNode, Node.JS, and SQL Server for event-based push notifications?

喜欢而已 提交于 2019-12-30 00:32:23
问题 For a notification project, would like to push event notifications out. These are things like login, change in profile, etc., and to be displayed to the appropriate client. I would like to discuss some ideas on putting it together, and get some advice on the best approach. I noticed here that changes made to a CouchDB can be detected with a _changes stream, picked up by Node, and a process kicks off. I would like to implement something like this (I'm using SQL Server, but an entry point at

Return total records from SQL Server when using ROW_NUMBER

房东的猫 提交于 2019-12-29 02:51:11
问题 I would like to return the total number of records in the database so I can set up pagination. How do I return the total number of records in the DB when using the following paging method in SQL Server 2008? ALTER PROCEDURE [dbo].[Nop_LoadAllOptimized] ( @PageSize int = 20, @PageNumber int = 1, @WarehouseCombinationID int = 1, @CategoryId int = 58, @OrderBy int = 0, @TotalRecords int = null OUTPUT ) AS BEGIN WITH Paging AS ( SELECT rn = (ROW_NUMBER() OVER ( ORDER BY CASE WHEN @OrderBy = 0 AND

How to check date of last change in stored procedure or function in SQL server

余生长醉 提交于 2019-12-29 02:18:30
问题 I need to check when function was changed last time. I know how to check creation date (it is in function properties window in SQL Server Management Studio). I found that in SQL Server 2000 it wasn't possible to check modify date ( look at this post: Is it possible to determine when a stored procedure was last modified in SQL Server 2000?) Is it possible to check it in SQL Server 2008? Does MS add some new feature in system tables that allow to check it? 回答1: SELECT name, create_date, modify

SQL Server 2008 Service Broker tutorial — cannot receive the message (exception in transmission_status)

ε祈祈猫儿з 提交于 2019-12-28 12:00:14
问题 I am learning how to use the Service Broker of SQL Server 2008 R2. When following the tutorial Completing a Conversation in a Single Database. Following the Lesson 1, I have successfully created the message types, contract, the queues and services. Following the Lesson 2, I have probably sent the message. However, when trying to receive the message, I get the NULL for the ReceivedRequestMsg instead of the sent content. When looking at the sys.transmission_queue , the transmission_status for

Deleting duplicate record in SQL Server

时光怂恿深爱的人放手 提交于 2019-12-28 04:05:50
问题 I have written a query to remove duplicate records from a table ;WITH a as ( SELECT Firstname,ROW_NUMBER() OVER(PARTITION by Firstname, empID ORDER BY Firstname) AS duplicateRecCount FROM dbo.tblEmployee ) --Now Delete Duplicate Records DELETE FROM tblEmployee WHERE duplicateRecCount > 1 But I don't know where I went wrong it is saying Invalid column name duplicateRecCount Can someone help me? 回答1: You need to reference the CTE in the delete statement... WITH a as ( SELECT Firstname,ROW

How do I find the data directory for a SQL Server instance?

冷暖自知 提交于 2019-12-28 03:29:05
问题 We have a few huge databases (20GB+) which mostly contain static lookup data. Because our application executes joins against tables in these databases, they have to be part of each developers local SQL Server (i.e. they can't be hosted on a central, shared database server). We plan on copying a canonical set of the actual SQL Server database files (*.mdf and *.ldf) and attach them to each developer's local database. What's the best way to find out the local SQL Server instance's data

Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)

非 Y 不嫁゛ 提交于 2019-12-28 01:39:29
问题 I have a development database that re-deploy frequently from a Visual Studio Database project (via a TFS Auto Build). Sometimes when I run my build I get this error: ALTER DATABASE failed because a lock could not be placed on database 'MyDB'. Try again later. ALTER DATABASE statement failed. Cannot drop database "MyDB" because it is currently in use. I tried this: ALTER DATABASE MyDB SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE but I still cannot drop the database. (My guess is that most of

TSQL Order BY on occasion doesn't order correctly

杀马特。学长 韩版系。学妹 提交于 2019-12-25 19:38:04
问题 TSQL MSSQL 2008r2 I'm re-writing the question to try and make it clear what the issue is that I'm trying to explain. I've got a stored proc that takes 3 parameters. VehicleKey, StartDate and EndDateTime. I'm querying a Data Warehouse db. So the data shouldn't change. When the proc is called with the same parameters then most of the time the results will be as expected but on some random occasions, with those same parameters, the results differ. I'm querying a Data WH so the data doesn't

Query Optimisation in SQL Server 2008 R2

£可爱£侵袭症+ 提交于 2019-12-25 18:34:35
问题 I know this question is asked frequently here but I have some different requirements. I want to get this output. I am getting this also with my logic but can this can be done in more simple and optimised way. To run this query faster. Here is my query: select ISNULL('PortFolio Code: '+a.CPORTFOLIOCODE,'Grand Total') as [PortFolio Code], COUNT(SZCUSTOMERNO) as [Accounts], CAST(COUNT(SZCUSTOMERNO) * 100 / (Select COUNT(SZCUSTOMERNO) from dbo.COL_TRN_AGREEMENT) as nvarchar(50))+' %' as [%], sum