sql-server-2008-r2

sql convert single row to key/value columns

大城市里の小女人 提交于 2019-12-04 13:57:50
问题 I have a SQL query returning 1 row, with multiple column headers: Col 1 | Col 2 | Col 3 val 1 | Val 2 | Val 3 is there a way to convert this row to 2 columns, i.e. : Col 1 | Val 1 Col 2 | Val 2 Col 3 | Val 3 this is running on SQLServer 2008 r2 EDIT: Adding a better example Product_Code | Product_Name | Customer_Name 101 | yummy cake | derps cake shop is coming from a simple select p.prod_code, p.prod_name, c.cust_name from product p inner join customer c on p.id = c.id type query. What I

SQL query to show change history of data

爱⌒轻易说出口 提交于 2019-12-04 13:48:51
I have a table in a SQL Server database which stores historical data on daily basis. The structure is shown below: UploadDate TypeID Value1 Value2 ------------------------------------------- 2012-01-08 1 NEG 1998-02-05 2012-01-08 2 NEG 1999-02-09 2012-01-08 3 STABLE 1997-02-06 2012-02-08 1 NEG 1998-02-05 2012-02-08 2 NEG 1999-02-09 2012-03-08 1 POS 2012-03-08 2012-03-08 2 STABLE 2012-01-08 As you can see above for the TypeID 1 & 2, Value1 and Value2 has changed on 2012-03-08 My requirement is such that I have to show only those rows which have changed from previous values. In this case since

Powershell Invoke-sqlcmd keeping connection open and trying to reuse it

烈酒焚心 提交于 2019-12-04 13:38:40
问题 I have a Powershell script that uses invoke-sqlcmd to apply scripts to a series of development databases. I loop through a list of scripts and compare it to the current release level of the database and then apply the required scripts to get the DB to the release level it needs to be at. Certain databases are reference databases and are in a READ_ONLY state. I connect to those database run an alter DB script setting them to READ_WRITE apply the script then change the back to READ_ONLY.

Is there any way/tool to identify estimate query run time in SQL sERVER

两盒软妹~` 提交于 2019-12-04 13:15:38
I have been google about this for a while..is there any way to identify the estimated query execution time> There are actual execution plan and estimated execution plan on the ssms .The thing is none of these have estimated time. Is it something lacking in the Sql Server? Peter Currently, no. Microsoft is currently researching ways to do this using a combination of work already completed and an estimated execution plan (See the details of their research on the Microsoft Research site ), so we can expect to see something soon. But this is the only development that I am aware of. The solution I

Table hiding in SQL Server database?

…衆ロ難τιáo~ 提交于 2019-12-04 12:42:18
I am transferring data into a table all of sudden I went throgh a crazy problem I have never seen in my career. Msg 208, Level 16, State 1, Line 1 Invalid object name 'dbo.Table_Report'. Then I tried to create a table with same name and again I got fallowing error Msg 2714, Level 16, State 6, Line 2 There is already an object named 'Table_Report' in the database. What went wrong I need to send data in to table asap but I am unable to do that at least I can't delete the table Cannot drop the table 'Table_Report', because it does not exist or you do not have permission. Note: I have admin rights

How to optimise the 'XQuery' SQL

两盒软妹~` 提交于 2019-12-04 12:23:42
I have an XML hierarchy like this in an XML type column of a table with 10,000 records- <Root> <Elem1> <Parent1> <Separator> <Child1/> </Separator> </Parent1> </Elem1> </Root> I have a query like this - DECLARE @Root VARCHAR(50) DECLARE @Entity VARCHAR(50) DECLARE @ParentNode VARCHAR(50) DECLARE @Separator VARCHAR(50) DECLARE @ChildNode VARCHAR(50) SET @Root = 'Root' SET @Entity = 'Elem1' SET @ParentNode = 'Parent1' SET @Separator = 'separator' SET @ChildNode = 'Child1' select Parent.P.value('.', 'varchar(max)') as MyValue, T.uniqueId, T.XMLCol from [XMLTable] as T cross apply (SELECT XMLTable

Alter column from NVARCHAR to NBINARY

﹥>﹥吖頭↗ 提交于 2019-12-04 12:03:22
I accidentally created a column with the wrong type NVARCHAR (for storing password salts) and I want to convert it to NVARBINARY . I tried ALTER TABLE [dbo].[TableName] ALTER COLUMN [ColumnName] [varbinary] (20) NOT NULL GO but it says Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query. Is there a way to do that? CONVERT seems to be for expressions only, not for alterations. The only way by altering will be someting like: Create Table a (id int,blb Nvarchar(10)) insert into a Values (1,'Test'), (2,N'Test2'); BEGIN Transaction

Why only some users get the error: “Connection is busy with results for another command”

流过昼夜 提交于 2019-12-04 12:01:42
问题 I have a Delphi Application that is connected to a SQL Server db using SDAC component from DevArt, we have 200 installations of the software and only to a customer, with some users, I notice the following error: "Connection is busy with results for another command" = "La connessione è occupata dai risultati di un altro comando". SQL vers. : SQL Server 2008 R2 Express with filestream full enabled My application create both db users and SQL account logins: creating a new user, then there aren't

sql error not thrown back to caller

只谈情不闲聊 提交于 2019-12-04 11:59:45
I am new to this forum but please bear with me. I have a c# Windows form which has two checkboxes on it One is called chkThrowError and the other is called chkDivideError, both are unchecked. These controls are purely there to control execution of a stored procedure. I have a command Button with the following Code: private void cmdError_Click(object sender, EventArgs e) { int ThrowError = 0; int DividByZero = 0; if (chkThrowError.Checked) { ThrowError = 1; } if (chkDivideError.Checked) { DividByZero = 1; } try { clsBBFinances.TestError(ThrowError,DividByZero); MessageBox.Show("Everything is

SQL Server Jobs with SSIS packages - Failed to decrypt protected XML node “DTS:Password” with error 0x8009000B

喜欢而已 提交于 2019-12-04 09:55:44
问题 i have a SQL server job that runs a SSIS package. This job has 9 steps and in each step it extracts data from a different database. the connections strings are defined as parameters in each step. im getting the following error when i run the job. Executed as user: USER\MYSERVER$. Microsoft (R) SQL Server Execute Package Utility Version 10.50.1600.1 for 64-bit Copyright (C) Microsoft Corporation 2010. All rights reserved. Started: 5:50:55 PM Error: 2013-06-21 17:50:55.44 Code: 0xC0016016