sql-server-2005

Rotating sql table

泄露秘密 提交于 2019-12-24 22:08:47
问题 my sql talble has the following structure F1 F2 F3 F4 F5 Group 1 2 3 4 Design 5 6 7 8 now i want to read this and return a query result as show below please help F1 Value Group 1 Group 2 Group 3 Group 4 Design 5 Design 6 Design 7 Design 8 回答1: SQL 2005 Introduced a pivot and matching unpivot clause, and this looks like a prime case, if you're unable to fix the underlying schema 回答2: You could use the UNION operator: SELECT F1, F2 AS VALUE FROM TABLE UNION SELECT F1, F3 AS VALUE FROM TABLE

SQL Query - Copy Values in Same Table

前提是你 提交于 2019-12-24 21:43:38
问题 So I have a table that looks like this: ProjectID TaskID Date 000 001 10/28/09 000 002 12/1/09 000 003 02/24/10 001 001 04/14/10 001 002 07/5/10 001 003 02/24/11 002 001 06/07/10 002 002 07/7/10 002 003 09/13/12 Assume there are many projects and many tasks, but each project contains the same tasks. I want to copy dates in the following manner: One project (000) has the master dates. I want to copy those dates for each task to several other projects (001, 002 in the example data). So, if task

How to order fields on index creation (SQL Server 2005 +)?

只谈情不闲聊 提交于 2019-12-24 21:20:02
问题 As this article's figure 4 says, SQL Server 2005 + can return you a list of missing indexes. It stores 2 important info about missing indexes: [EqualityUsage],[InequalityUsage] If I have a missing index where: [EqualityUsage]='col1',[InequalityUsage]='col2' Should I create an index with Indexed Key Columns: 'col1,col2' or 'col2,col1' ? 回答1: col1, col2 CREATE INDEX To convert the information returned by sys.dm_db_missing_index_details into a CREATE INDEX statement, equality columns should be

Changing the Datatype of table column

本秂侑毒 提交于 2019-12-24 21:07:18
问题 A very simple MSSQL command is giving error. create table emp (empid char(6)); insert into emp values(3); ALTER TABLE emp MODIFY empid char(10); //The error line :@ Error >Line 1: Incorrect syntax near 'empid'. It's mindboggling, either the day is not mine or All Hail MS :P Any resolutions? 回答1: Change it to ALTER TABLE emp ALTER COLUMN empid char(10) Have a look at ALTER TABLE (Transact-SQL) and search for ALTER COLUMN examples 来源: https://stackoverflow.com/questions/1979883/changing-the

Convert XML to table in SQL Server 2005

帅比萌擦擦* 提交于 2019-12-24 20:25:05
问题 If I pass in an xml parameter to a stored proc which looks like this: <ClientKeys> <ck>3052</ck> <ck>3051</ck> <ck>3050</ck> <ck>3049</ck> ... </ClientKeys> ...and then convert the XML to a temp table like this: CREATE TABLE #ClientKeys ( ClientKey varchar(36) ) INSERT INTO #ClientKeys (ClientKey) SELECT ParamValues.ck.value('.','VARCHAR(36)') FROM @ClientKeys.nodes('/ClientKeys/ck') as ParamValues(ck) ...the temp tbl is populated and everything is good. However the time taken to populate

Why would a schema make an XML column slower?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 19:37:12
问题 I have a table with an XML column. The documents are pretty large and numerous, and I've been trying various ways to improve the performance of basic queries. Because the documentation indicates that applying an XML Schema to the column can help SQL Server to optimize queries — and because one was available — I created a schema collection and applied the type to my XML column. Query performance went off a cliff. I mean, the very simplest tests became intolerably slow. I removed the column

Looks simple, but I'm stumped!

我是研究僧i 提交于 2019-12-24 19:23:31
问题 This should be so simple, but I'm drawing a blank. I have two tables. Table:article_tag_pvt colum: article_id column: tag_id Table: tag column: tag_id column: name The article_tag_pvt table is a many-to-many pivot table. The problem is, I need a query which given a list of tag names, will retrieves article Ids which ONLY match those tag names. The basic joining of these tables looks like this: SELECT article_id FROM article_tag_pvt pvt INNER JOIN tag t ON t.tag_id = pvt.tag_id I've already

Changing an SSIS dts variables

只愿长相守 提交于 2019-12-24 19:01:16
问题 In an SSIS package I have a For..Each container that enumerates all ( . ) the files in a folder. In that For..Each container I have a component-level variable 'fileComments' of DataType 'String'. In that For..Each container I have a script task. With a ReadWrite entry for 'filecomments' (amongst others) In that script task, I have some code :- Dim Comments As String = Dts.Variables("User::fileComments").ToString which allows me to read the value of that variable, but if I try to allocate a

Subsonic 3/ASP.net mvc trying to save a null value in a datetime column

情到浓时终转凉″ 提交于 2019-12-24 18:58:13
问题 I have a table that holds system users with their last login date and time in it. The admin users of the system need to be able to add users, but when I add the new user record a validation error occurs unless I put a valid datetime in the last login date field. I've tried manually changing the field to dbnull, null, etc prior to the save but it says those values cannot be converted to datetime. The column does allow nulls in the db. Any suggestions? 回答1: If you set LastLogin to be DateTime?

Adding a logical key to a View in SQL Server Manager

╄→尐↘猪︶ㄣ 提交于 2019-12-24 18:37:52
问题 The .NET Entity framework is giving me the following error: "The table/view 'Foo.dbo.vwFoo' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity you will need to review your schema, add the correct keys and uncomment it." The view is a collection of a variety of tables and calculations. What I'd like to do is create a "logical key" using one of the columns that I know should be unique. I can't figure out how to do