sql-server-2012

How can I group on the SAME table, order by date and limit the number of rows returned?

对着背影说爱祢 提交于 2019-12-12 03:28:52
问题 I would like to return a set that is grouped by ID_F, limited in count within ID_F and sorted by date within ID_F Here is my database setup: CREATE TABLE [dbo].[U]( [ID] [uniqueidentifier] NOT NULL, [Name] [nvarchar](max) NULL, CONSTRAINT [PK_U] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[F]( [ID] [uniqueidentifier] NOT NULL, [Name]

Find non-duplicate records, excluding nulls, based on one field.

痴心易碎 提交于 2019-12-12 03:28:35
问题 I want to find all unique records in the Dat1 field, but I want every single Null record returned. It doesn't matter which duplicate record is dropped. Example Table: +----+--------------+ | ID | Dat1 | +----+--------------+ | 1 | 11@email.com | | 2 | 11@email.com | | 3 | NULL | | 4 | NULL | | 5 | 99@email.com | | 6 | 99@email.com | +----+--------------+ Desired Result: +----+--------------+ | ID | Dat1 | +----+--------------+ | 1 | 11@email.com | | 3 | NULL | | 4 | NULL | | 5 | 99@email.com

Case statement not correctly matching expected values

时间秒杀一切 提交于 2019-12-12 03:24:22
问题 I'm trying to generate some randomized data, and I've been using newid() to seed functions since it is called once for every row and is guaranteed to return a different result each time. However I'm frequently getting values that are somehow not equal to any integers in the expected range. I've tried a few variations, including a highly upvoted one, but they all result in the same issue. I've put it into a script that shows the problem: declare @test table (id uniqueidentifier) insert into

Transfer Access DB to SQL Server DB using SSIS

丶灬走出姿态 提交于 2019-12-12 03:13:54
问题 How can I transfer a full database from Access to SQL Server 2012 using SQL Server Integration Services? 回答1: Yes you can do this. You need BIDS and just create a control flow and task flows with what you want to do. SSIS is simple drag and drops for the most part 回答2: Another solution is to use the Import/Export wizard. Simply right click on a database in SQL Server, choose Tasks > Import Data. The wizard will walk you through the setup. At the end you can save the package which then can be

SQL Server Job runs successfully, but doesn't execute packages

谁说胖子不能爱 提交于 2019-12-12 02:59:43
问题 We have SQL Server 2012. We got .dtsx packages that run just fine. We run them manually and they execute properly, but when they are setup to be executed as SQL Server Job, the job executes successfully (no errors), but the SSIS packages are never executed. Nothing happens. What would be the case? Permissions on packages are setup on FULL for SQLServerAgent user and same user is setup to be the owner of that job. Also that same user is setup to be DB admin on server. Any clues how to resolve

SQL 2012 - Pivot and Unpivot

三世轮回 提交于 2019-12-12 02:56:33
问题 I have summarised data in a table which is similar to this: Customer Year Month No_trans spend points 1 2015 1 30 400 10 1 2015 2 20 150 5 1 2015 3 10 500 15 2 2015 1 5 100 7 I would like to try and use Pivot/Unpivot to change to this, is it possible? ?????? Customer 2015_1 2015_2 2015_3 No_trans 1 30 20 10 Spend 1 400 150 500 Points 1 10 5 15 No_trans 2 5 0 0 Spend 2 100 0 0 Points 2 7 0 0 Thanks 回答1: You could use dynamic SQL to transpose table: DECLARE @cols NVARCHAR(MAX) = STUFF((SELECT

Calculating total time in a place with SQL Server datetime

别来无恙 提交于 2019-12-12 02:52:34
问题 I am new to SQL and I was wondering if the following is even possible to achieve. Using SQL Server 2012 I would like to find the total time a given entity has spent in one location in minutes. There are multiple entries for each entity as they may have gone in and out of a given location many times during the day, I just want to find the total time spent in minutes for all the time spent for a given location. The table has two datetime columns that display Starttime and Endtime , along with

Could not access the SSO database During biztalk runtime Configuration

风流意气都作罢 提交于 2019-12-12 02:48:02
问题 I'm trying to test a migration of moving a BizTalk SQL Server from one server to another. Here are the details. Currently it was all on a single server in a dev environment, BizTalk SQL, SSO and BizTalk runtime all on one server. It is a Windows 2008 R2 server with SQL Server 2008 R2. What I want to do is split out the SSO Master secret server and BizTalk databases to a Windows Server 2012/SQL Server 2012 setup. So far I got SSO all setup on the new SQL server. I configured just the SSO

How to split string into multiple in sql server

走远了吗. 提交于 2019-12-12 02:30:06
问题 I'm Having a column data like below, 126-35-56-24 And I want the results be like, select 126 as Id, 35 as Age, 56 as EmpId, 24 as Day I just try using substring and I can Able to split the string into 126 and 35-56-24, but I can't get the result I Want. Please help me to get this. Thanks in Advance... 回答1: Use the below script ,which will split the strings based on the char index of '-'. DECLARE @data varchar(50)='126-35-56-24' SELECT 'SELECT '+ SUBSTRING(@data,1,CHARINDEX('-', @data)-1) + '

Executing a Stored Procedure on a Linked Server

柔情痞子 提交于 2019-12-12 02:19:25
问题 I am running SQL Server 2012 on two separate servers (let's call them Server A and Server B). On Server A, I have created a linked server to Server B called [ServerB]. I am able to query Server B from Server A without any problems: SELECT * [ServerB].[MyDatabase].[dbo].[MyTable] However, when I try to execute a stored procedure: EXEC [ServerB].[MyDatabase].[dbo].[MyStoredProcedure] ...I get the following error: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. I've done a lot of Googling