sql-server-2005

Request joining the results of two other requests with GROUP BY clause in SQL Server 2005

狂风中的少年 提交于 2019-12-24 14:09:31
问题 I often find myself doing something along the following lines in sql server 2005 : Step1: create view view1 as select count(*) as delivery_count, clientid from deliveries group by clientid; Step2: create view view2 as select count(*) as action_count, clientid from routeactions group by clientid; Step3 : select * from view1 inner join view2 on view1.clientid = view2.clientid Is it possible to obtain the same final result in only one statement, avoiding the creation of the views ? 回答1: Sure,

Store audio in SQL Server?

牧云@^-^@ 提交于 2019-12-24 13:33:03
问题 Is it a good idea to store audio files (mp3, wav) in SQL Server as BLOBs? One of the merits appears to be saving Hard disk space. Does this have any impact on scalability or performance? 回答1: No, it's not a good idea :) Variable-sized fields (such as TEXT and BLOB) have all sorts of performance impacts. A better approach is store the files on disk and just maintain a reference to them in a DB table. Nowadays, hard drive space is so cheap (especially compared to CPU and I/O performance) that

TSQL - Recursively select date between 2 given dates

不问归期 提交于 2019-12-24 13:15:42
问题 I have table in my db called Tasks . Every record in that table has 2 fields: StartDate , EndDate I need to create recursive stored procedure that will send mails in middle of those dates. For example: Start is 2013-10-22 12:00:00:000 End is 2013-10-24 12:00:00:000 I can do: SELECT DATEADD(ms, DATEDIFF(ms,'2013-10-22 12:00:00:000', '2013-10-24 12:00:00:000')/2, '2013-10-22 12:00:00:000') and then check if now is greater than that date, if Yes then I can send mail. But I need to do that

Using WITH(NOLOCK) to increase performance

天大地大妈咪最大 提交于 2019-12-24 12:51:57
问题 I have seen developers using WITH(nolock) in the query, is there any disadvantage of it? Also, what is the default mode of execution of query? My database do not have any index. Is there any other way to increase database select statement performance? 回答1: The common misconception with nolock is that that it places no locks on the database whilst executing. Technically it does issues a schema-stability (sch-s) lock, so the 'no' part of the lock relates to the data side of the query. Most of

TSQL - Case Date Compare

余生长醉 提交于 2019-12-24 12:11:52
问题 I am trying to compare a date in SQL and create a new field to allow me to group the results by Todays date and other date(s). I am converting both dates to CHAR. However i am getting an expression error near = and ) - This is for an SSRS report. There is already a fairly complex SQL statement and i am just trying to add this extra statement to help in grouping. Here is an example. Case WHEN Convert(Char(8), FieldDate, 103) = Convert(Char(8), GetDate(), 103) Then tmpDate = '1' ELSE tmpDate =

Why EclipseLink maps a NVARCHAR type to an Object?

余生长醉 提交于 2019-12-24 11:44:19
问题 I am using the latest version of EclipseLink (2.2.0) with SQL Server 2005. Generating the classes, the type NVARCHAR is mapped to type Object in the classes. I suppose it should map to type String. Why is this happening? 回答1: How are you generating the classes? Are you using Eclipse Dali? I would just change the generate code to String. Perhaps report a bug with the IDE you are using. EclipseLink itself, does not generate classes. 来源: https://stackoverflow.com/questions/5883670/why

Couting combinations within a group

 ̄綄美尐妖づ 提交于 2019-12-24 11:34:27
问题 I need a way way to count combinations of code by patients, so I need to know based on this report total duration of each Service Program Protocol, so based on the picture below I need it to be like this Patient: 00000036 Adult CSS IND 240 Adult OP IND 120 Patient: 00000040 Adult CSS IND 420 Adult OP IND 60 I am using Microsoft SQL Server 2005 and I would prefer a fix in SQL, but if it could be done in crystal I could work with that. Thank you in advance. select pct.patient_id, pct.clinic_id,

Can this be simplified and therefore optimized

主宰稳场 提交于 2019-12-24 11:12:31
问题 We have this data set: CREATE TABLE #Changes ( [GUID] varchar(250), Value numeric(36,6), DocumentNumber varchar(250), Approved bit, ApprovedDate varchar(250), IssuedDate varchar(250), Category varchar(250) ); INSERT INTO #Changes ( [GUID], DocumentNumber, Approved, Value, ApprovedDate, IssuedDate, Category ) values ('4F7253A4E1B3D841B84D4A82B4F0E7A2', 11, 0, 18526.7, '', '2009-03-31T05:00:00Z', 'UNKNOWN'), ('D97537852E927B499C21C14F3D13CF06', 1, 0, 0, '', '2008-11-10T05:00:00Z', 'UNKNOWN'), (

How to get SQL query to not escape HTML data returned in query

被刻印的时光 ゝ 提交于 2019-12-24 11:09:14
问题 I have the following SQL query.... select AanID as '@name', '<![CDATA[' + Answer + ']]>' from AuditAnswers for XML PATH('str'), ROOT('root') which works wonderfully but the column 'Answer' can sometimes have HTML markup in it. The query automatically escapes this HTML from the 'Answer' column in the generated XML. I don't want that. I will be wrapping this resulting column in CDATA so the escaping is not necessary. I want the result to be this... <str name="2"><![CDATA[<DIV><DIV Style="width

INSERT INTO @table_name…EXEC usp_name

限于喜欢 提交于 2019-12-24 10:56:46
问题 I've read in a lot of web sites that the following code will not work, where @table_name is a table variable: INSERT INTO @table_name EXEC usp_name usp_param1, usp_param2 But the above exact code works fine for me inside a stored procedure in SQL Server 2005 (version 9.0.4035). Even MSDN (URL: http://msdn.microsoft.com/en-us/library/aa260638%28v=SQL.80%29.aspx) mentions that the insert code will not work if an attempt to club insert with exec is executed on a table variable. Unfortunately,