sql-server-2005

Select parent and child from the same table

。_饼干妹妹 提交于 2020-01-14 06:03:49
问题 I have a emp table, CREATE TABLE [dbo].[Emp]( [EmpId] [int] NULL, [EmpName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ManagerId] [int] NULL ) ON [PRIMARY] Now, insert below values into the table Insert Into Emp Values(1,'A',0) Insert Into Emp Values(2,'B',1) Insert Into Emp Values(3,'C',2) Insert Into Emp Values(4,'D',2) Insert Into Emp Values(5,'E',4) Insert Into Emp Values(6,'F',4) Insert Into Emp Values(7,'G',4) Insert Into Emp Values(8,'H',6) Insert Into Emp Values(9,'I'

sql max/min query and data transformation

北慕城南 提交于 2020-01-14 05:34:07
问题 update: changed one time to show that the times per shipment may not be in sequential order always. here is my input create table test ( shipment_id int, stop_seq tinyint, time datetime ) insert into test values (1,1,'2009-8-10 8:00:00') insert into test values (1,2,'2009-8-10 9:00:00') insert into test values (1,3,'2009-8-10 10:00:00') insert into test values (2,1,'2009-8-10 13:00:00') insert into test values (2,2,'2009-8-10 14:00:00') insert into test values (2,3,'2009-8-10 20:00:00')

Sql Server 2012 slower than 2005?

℡╲_俬逩灬. 提交于 2020-01-14 05:18:12
问题 We have deployed SQL Server 2012 Enterprise and we have performance issues: same data (backuped from our SQL Server 2005 Enterprise and restored on 2012) test script of 3200 sql SELECT statements We do tests using Management Studio: results as plain text results in a file On same computer: 2005 : 15 sec, 2012 : 2 min 2005 : 14 sec, 2012 : 30 sec Even with a more powerful computer, 2012 is still slower than 2005. What can be wrong? The way we installed SQL Server 2012 and default parameters?

subsonic 3.0 , The SqlServer default value doesn't work?

*爱你&永不变心* 提交于 2020-01-14 03:46:07
问题 I used subsonic 3 with T4,It's very simple to use.But I get a problem now.I specify the default value in the sqlserver 2005.Then I called save() method in subsonic.I found the default value doesn't work. 回答1: Default values won't work on inserts because your object will set the value first - whether it's null or ... whatever. The answer here is to set the default on the object. 来源: https://stackoverflow.com/questions/1171025/subsonic-3-0-the-sqlserver-default-value-doesnt-work

Extending MembershipProvider

怎甘沉沦 提交于 2020-01-14 02:48:37
问题 Scenario: Building an application for companies to enter information into. I need to extend the built-in membership provider in asp.net. My unique situation is that I already have demographic information for each company, but NOT userid's and passwords for a web app. I want to prepopulate the DB with the demographic information, send each company a unique pin number, and ask them to register with my application. I want them to create a userid, email address and password, after they've

Querying for a unique value based on the aggregate of another value while grouping on a third value entirely

家住魔仙堡 提交于 2020-01-14 02:16:06
问题 So I know this problem isn't a new one, but I'm trying to wrap my head around it and understand the best way to deal with scenarios like this. Say I have a hypothetical table 'X' that looks like this: GroupID ID (identity) SomeDateTime -------------------------------------------- 1 1000 1/1/01 1 1001 2/2/02 1 1002 3/3/03 2 1003 4/4/04 2 1004 5/5/05 I want to query it so the result set looks like this: ---------------------------------------- 1 1002 3/3/03 2 1004 5/5/05 Basically what I want

Usage of nested using in C# and SQL Server

空扰寡人 提交于 2020-01-13 21:37:50
问题 This thread is a continuation of Is there a reason to check for null inside multiple using clausule in c#? I've noticed that resharper lets me define using without opening any opening/closing bracket like in the method below (but then i can't use defined vars later on if the brackets ain't there, other then the one that is used exactly beneath defined using): public static string sqlGetDatabaseRows() { string varRows = ""; const string preparedCommand = @" SELECT SUM(row_count) AS 'Rows' FROM

SQL Server - Adding an XML Index to a calculated column on a View

∥☆過路亽.° 提交于 2020-01-13 20:43:07
问题 I have a table which stores comma separated values in an NVARCHAR(MAX). I have created a view, which uses string manipulation to convert these comma separated values into an xml list. I can then use this Xml column access each item. The queries on this column will benefit greatly if I could index it. However, on trying to create a Primary XML index I get the message "View XmlFoo foes not have a clustered primary key. Creation of an XML index requires a clustered primary key on the view." Is

Removing duplicate records

折月煮酒 提交于 2020-01-13 20:35:55
问题 I am using the following query SELECT SS.sightseeingId AS 'sID' , SS.SightseeingName , SS.displayPrice AS 'Price' , SST.fromDate FROM tblSightseeings SS INNER JOIN tblSightseeingTours SST ON SS.sightseeingId = SST.sightseeingId WHERE SS.isActive = 1 AND SS.isDisplayOnMainPage = 1 and getting result like this sID | SightseeingName | Price | fromDate ------------------------------------------------------------------------------ 2 | Dinner Cruise Bateaux London (Premier) | 40 | 2009-04-01 00:00

sp_executesql with 'IN' statement

混江龙づ霸主 提交于 2020-01-13 18:34:15
问题 I am trying to use sp_executesql to prevent SQL injection in SQL 2005, I have a simple query like this: SELECT * from table WHERE RegionCode in ('X101', 'B202') However, when I use sp_executesql to execute the following, it doesn't return anything. Set @Cmd = N'SELECT * FROM table WHERE RegionCode in (@P1)' SET @ParamDefinition = N'@P1 varchar(100)'; DECLARE @Code as nvarchar(100); SET @Code = 'X101,B202' EXECUTE sp_executesql @Cmd, @ParamDefinition, @P1 = @Code The is what I have tested: SET