sql-server-2008-r2

SQL Server: EXECUTE AS clause of stored procedure not granting sysadmin permissions

眉间皱痕 提交于 2019-12-10 20:31:48
问题 I developped a stored procedure in order to restore a database from a backup file and add an application user to it. This stored procedure belongs to the master database. The issue is that my IT department does not allow me to use an admin user, only to use an EXECUTE AS statement with a sysadmin user. I can restore the database but I can't find a way to add the user at the end of the process. The code I use: CREATE PROCEDURE [dbo].[myProc] @database VARCHAR(50) WITH EXECUTE AS 'aSysAdminUser

SQL Server : splitting the results of GROUP BY into a separate columns

久未见 提交于 2019-12-10 19:43:47
问题 I've got a SQL Server 2008 R2 database with around 500 million rows of data in it, it currently looks like this ID Eventtype 201 1 201 3 201 4 201 1 201 1 664 1 664 0 664 1 664 3 I can't seem to find a query that will provide the data back in this format: ID Event0 Event1 Event2 Event3 Event4 201 0 3 0 1 1 664 1 2 0 1 0 This is as far as I've gotten at this point: select distinct ID as ID, count(EventType) from database.dbo.events group by questID, EventType which spits data back to me like:

Will SSDT-BI work with SQL Server 2008 R2?

依然范特西╮ 提交于 2019-12-10 18:23:43
问题 Can some one tell me whether the SSIS packages developed in Visual Studio 2012 or 2013 works in 2008r2 server or not ??? If yes, did any other software needs to be installed in the 2008r2 server? Deployment is not any concern here. I just want to run the packages in 2008r2 server via sql agent job Please help. 回答1: No. Backwards compatibility is not an option. A package built in 2014 will not run on 2012. A 2012 package will not run on 2008 and a 2008 package will not run on 2005. However,

F# LINQ add new rows to SQL Server

自作多情 提交于 2019-12-10 17:36:07
问题 I am learning LINQ with F# 3.0. I want to know how to re-write my old code to use new LINQ features in F# 3.0 For example, I have created a simple data table in SQL Server 2008 R2, the database name is myDatabase. -- Create the Table1 table. CREATE TABLE [dbo].[Table1] ( [Id] INT NOT NULL, [TestData1] INT NOT NULL, [TestData2] FLOAT (53) NOT NULL, [Name] NTEXT NOT NULL, PRIMARY KEY CLUSTERED ([Id] ASC) ); For F# 2.0, I can use Dataset to add new rows, like this: #light open System open System

Why doesn't a trailing comma after the last field matter when creating a table using T-SQL?

ε祈祈猫儿з 提交于 2019-12-10 17:24:31
问题 Shouldn't one of these statements work and one fail? Intuition says Statement 2 should fail because there is a comma after int and no second column listed. Yet both work and the trailing comma "," after the last column data type makes no difference. -- Statement 1 CREATE TABLE dbo.MyTable1( col1 int); -- Statement 2 CREATE TABLE dbo.MyTable2( col1 int,); However (and this is expected): two commas ",," after the last field do cause a failure: -- Statement 3 CREATE TABLE dbo.MyTable3( col1 int,

How to use calculated field in another field of the same query

守給你的承諾、 提交于 2019-12-10 17:12:26
问题 I have a select query with a few dozen fields. "FieldA" is a Case statement about 10 rows tall. I now have to make a "FieldB" which uses the same Case statement plus a constant. With my current knowledge of sql-server, I'd have to repeat that Case statement twice (once for FieldA and once for FieldB). To clean up my code, how can I use fieldA in the calculation of FieldB? Ideally, my code would look something like this: Select Case ... When ... then ... When ... then ... When ... then ... End

How to update each row of a table with a random row from another table

若如初见. 提交于 2019-12-10 16:50:12
问题 I'm building my first de-identification script, and running into issues with my approach. I have a table dbo.pseudonyms whose firstname column is populated with 200 rows of data. Every row in this column of 200 rows has a value (none are null). This table also has an id column (int, primary key, not null) with the numbers 1-200. What I want to do is, in one statement, re-populate my entire USERS table with firstname data randomly selected for each row from my pseudonyms table. To generate the

How to make row numbering with ordering, partitioning and grouping

六眼飞鱼酱① 提交于 2019-12-10 16:32:11
问题 I need to make row numbering with ordering, partitioning and grouping. Ordering by IdDocument, DateChange , partitioning by IdDocument and grouping by IdRole . The problem is in grouping especially. As it could be seen from the example ( NumberingExpected ) DENSE_RANK() must be the best function for this purpose but it makes repetition of numbering only when the values which are used to order are the same. In my case values used for ordering ( IdDocument, DateChange ) are always different and

Import multiple Excel files into SQL Server 2008 R2 using SSIS Packages?

只愿长相守 提交于 2019-12-10 16:29:45
问题 I have to insert data into two tables from two different excel sheets using SSIS packges. So, please some one tell me How to import multiple Excel files into SQL Server 2008 R2 using SSIS Packages? 回答1: since you have only 2 excel files and only two tables I don't see why use a foreach loop. Just follow this link and do it directly If you need to insert from both excel files to both databases you can use a multicast component to create a copy of a dataset 回答2: Use Foreach Loop Container -->

Best way to store quarter and year in SQL Server?

淺唱寂寞╮ 提交于 2019-12-10 15:53:47
问题 What would be the best way to store Quarter and Year in database? I have payments table and I need to assign quarter/year so that it's easy to tell for which quarter the payment was made. I was thinking on: a) adding two int columns to each payment b) adding another table and add possible values up to 5 years ahead and use the ID to join that table with payments one. What are other options? Maybe some is better or/and easier to maintain. This database will be used with C# program. 回答1: If you