sql-server-2005

SQL Server primary key on datetime field

烈酒焚心 提交于 2019-12-23 08:23:16
问题 I'm creating a new table in SQL Server 2005 that needs 2 fields: DateTime and MyValue (Int32). The DateTime field will be unique so I will be setting a unique constraint on it. Which table structure is better and why? MyIndex (PK, int) MyDate (datetime) (IX_UniqueKey) MyValue (int) or MyDate (PK, datetime) MyValue (int) My feeling is that I don't want an artificial PK (MyIndex) in this table because it is unnecessary and because the dates will be unique I will use them to access any record.

How to get the xml-safe version of an sql server XML Column

巧了我就是萌 提交于 2019-12-23 08:01:37
问题 Is there a way to get the xml-safe version of an xml column in sql server ? By xml-Safe i mean escaping special characters like <,>,', &, etc. I'd like to avoid doing the replacements myself. Is there a build in function in sql server. What I want to achieve is to store the xml content into another xml attribute. 回答1: I assume that by xml-safe you mean escaping of XML special tags. If you have an XML column you wish to include in another XML document then you have two options: project the

How to get the xml-safe version of an sql server XML Column

余生颓废 提交于 2019-12-23 08:00:07
问题 Is there a way to get the xml-safe version of an xml column in sql server ? By xml-Safe i mean escaping special characters like <,>,', &, etc. I'd like to avoid doing the replacements myself. Is there a build in function in sql server. What I want to achieve is to store the xml content into another xml attribute. 回答1: I assume that by xml-safe you mean escaping of XML special tags. If you have an XML column you wish to include in another XML document then you have two options: project the

MS SQL Server 2005 - Stored Procedure “Spontaneously Breaks”

感情迁移 提交于 2019-12-23 07:46:26
问题 A client has reported repeated instances of Very strange behaviour when executing a stored procedure. They have code which runs off a cached transposition of a volatile dataset. A stored proc was written to reprocess the dataset on demand if: 1. The dataset had changed since the last reprocessing 2. The datset has been unchanged for 5 minutes (The second condition stops massive repeated recalculation during times of change.) This worked fine for a couple of weeks, the SP was taking 1-2

Query: find rows that do not belong to a list of values

喜夏-厌秋 提交于 2019-12-23 07:46:02
问题 Lets consider I have a table 'Tab' which has a column 'Col' The table 'Tab' has this data - Col 1 2 3 4 5 If I have a set of values (2,3,6,7). I can query the values that are present in the table and the list by suing the query Select Col from Tab where col IN (2,3,6,7) But, if I want to return the values in the list that are not present in the table i.e. only (6,7) in this case. What query should I use? 回答1: The problem I believe is that your trying to find values from you in statement. What

Query: find rows that do not belong to a list of values

拥有回忆 提交于 2019-12-23 07:44:16
问题 Lets consider I have a table 'Tab' which has a column 'Col' The table 'Tab' has this data - Col 1 2 3 4 5 If I have a set of values (2,3,6,7). I can query the values that are present in the table and the list by suing the query Select Col from Tab where col IN (2,3,6,7) But, if I want to return the values in the list that are not present in the table i.e. only (6,7) in this case. What query should I use? 回答1: The problem I believe is that your trying to find values from you in statement. What

How to convert DateTime to a number with a precision greater than days in T-SQL?

瘦欲@ 提交于 2019-12-23 07:29:17
问题 Both queries below translates to the same number SELECT CONVERT(bigint,CONVERT(datetime,'2009-06-15 15:00:00')) SELECT CAST(CONVERT(datetime,'2009-06-15 23:01:00') as bigint) Result 39978 39978 The generated number will be different only if the days are different. There is any way to convert the DateTime to a more precise number, as we do in .NET with the .Ticks property? I need at least a minute precision. 回答1: Well, I would do it like this: select datediff(minute,'1990-1-1',datetime) where

Best practice between these two queries

坚强是说给别人听的谎言 提交于 2019-12-23 07:26:04
问题 I was in a user group meeting yesterday and they pointed out that using parameterized queries is better than harcoding the query. That got me to thinking, does this do anything beneficial(obviously on a much bigger scale than this though): DECLARE @Client1 UNIQUEIDENTIFIER, @Client2 UNIQUEIDENTIFIER SET @ClientId1 ='41234532-2342-3456-3456-123434543212'; SET @ClientId2 = '12323454-3432-3234-5334-265456787654'; SELECT ClientName FROM dbo.tblclient WHERE id IN (@Client1,@Client2) As opposed to:

Best practice between these two queries

99封情书 提交于 2019-12-23 07:25:05
问题 I was in a user group meeting yesterday and they pointed out that using parameterized queries is better than harcoding the query. That got me to thinking, does this do anything beneficial(obviously on a much bigger scale than this though): DECLARE @Client1 UNIQUEIDENTIFIER, @Client2 UNIQUEIDENTIFIER SET @ClientId1 ='41234532-2342-3456-3456-123434543212'; SET @ClientId2 = '12323454-3432-3234-5334-265456787654'; SELECT ClientName FROM dbo.tblclient WHERE id IN (@Client1,@Client2) As opposed to:

Insert Into temp table from a stored procedure that returns multiple result sets

南楼画角 提交于 2019-12-23 07:19:05
问题 Consider the following sql A stored proc called myProc which returns two result sets. Result set 1 returns column1, column2. Result set 2 returns column 3, column 4, column 5. The following sql will fail since the temp table only has defined 2 int columns. Create Table #temp1( Column1 int, Column2 int) insert into #temp1 exec myProc My question is is it possible to just insert the first result set into #temp1? 回答1: Old post, but I faced the same problem and although the answers mentioned